import{k as W,j as N,t as q,h as T,m as x,n as y,p as $,q as I,v as C,i as z,A as h,x as Y,s as B}from"./web.Os7kOAdY.js";import{c as G}from"./clipboard.BNxbz_oK.js";import{g as L,t as K}from"./i18n-runtime._BAkvU05.js";var Q=h('<div class=panel style=display:flex;flex-direction:column;gap:14px><div class=tool-field><span class=tool-label></span><input class=tool-input placeholder="0 9 * * 1-5"style=font-family:ui-monospace,monospace;font-size:16px><!$><!/></div><div class=tool-actions><span class=tool-label style=margin-right:6px></span><!$><!/></div><!$><!/><p class=tool-hint>'),U=h("<span class=tool-hint style=margin-top:6px>"),V=h("<span class=tool-error style=margin-top:6px>× <!$><!/>"),X=h("<button class=tool-cat-pill>"),Z=h("<div class=tool-field><span class=tool-label></span><pre class=tool-pre></pre><div class=tool-actions style=margin-top:8px><button class=tool-btn>");function S(n,e,l,s){const t=n.split(","),o=new Set;let u=[];for(const i of t){let r=1,c=i;const _=c.indexOf("/");if(_>=0&&(r=parseInt(c.slice(_+1),10),c=c.slice(0,_),!r||r<1))throw new Error(`步长非法: ${i}`);let g=e,p=l;if(c!=="*")if(c.includes("-")){const[f,m]=c.split("-");g=E(f,s)??parseInt(f,10),p=E(m,s)??parseInt(m,10)}else g=p=E(c,s)??parseInt(c,10);if(isNaN(g)||isNaN(p)||g<e||p>l||g>p)throw new Error(`字段非法: ${i}`);for(let f=g;f<=p;f+=r)o.add(f);u.push(ee(i,e,l,g,p,r,s))}return{values:[...o].sort((i,r)=>i-r),desc:u.join("，")}}function E(n,e){if(!e)return null;const l=e.findIndex(s=>s.toLowerCase()===n.toLowerCase());return l>=0?l:null}function ee(n,e,l,s,t,o,u){const a=i=>u?u[i]:String(i);return n==="*"?o===1?"每个":`每 ${o}`:s===t?a(s):s===e&&t===l?o===1?"每个":`每 ${o}`:`${a(s)}-${a(t)}`+(o>1?`/${o}`:"")}const te=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ne=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function se(n){try{const e=n.trim().split(/\s+/);let l=!1;if(e.length===6)l=!0;else if(e.length!==5)throw new Error("cron 必须为 5 或 6 段");let s=0;const t=l?S(e[s++],0,59):void 0,o=S(e[s++],0,59),u=S(e[s++],0,23),a=S(e[s++],1,31),i=S(e[s++],1,12,te),r=S(e[s++],0,6,ne),c=`分钟: ${o.desc} · 小时: ${u.desc} · 月份日: ${a.desc} · 月份: ${i.desc} · 星期: ${r.desc}`+(l?` · 秒: ${t.desc}`:"");return{ok:!0,fields:{sec:t,min:o,hour:u,dom:a,mon:i,dow:r},hasSec:l,desc:c}}catch(e){return{ok:!1,err:e.message}}}function le(n,e,l){const s=[],t=new Date(e.getTime());n.hasSec?t.setSeconds(t.getSeconds()+1,0):(t.setSeconds(0,0),t.setMinutes(t.getMinutes()+1));for(let o=0;o<1e5&&s.length<l;o++)(!n.hasSec||n.fields.sec.values.includes(t.getSeconds()))&&n.fields.min.values.includes(t.getMinutes())&&n.fields.hour.values.includes(t.getHours())&&n.fields.mon.values.includes(t.getMonth()+1)&&n.fields.dom.values.includes(t.getDate())&&n.fields.dow.values.includes(t.getDay())&&s.push(new Date(t.getTime())),n.hasSec?t.setSeconds(t.getSeconds()+1):t.setMinutes(t.getMinutes()+1);return s}const oe=[{k:"每分钟",v:"* * * * *"},{k:"每小时整点",v:"0 * * * *"},{k:"每天凌晨",v:"0 0 * * *"},{k:"工作日 9 点",v:"0 9 * * 1-5"},{k:"每周一 8:30",v:"30 8 * * 1"},{k:"每月 1 号",v:"0 0 1 * *"},{k:"每 5 分钟",v:"*/5 * * * *"},{k:"每 30 秒（含秒）",v:"*/30 * * * * *"}];function ce(){const[n,e]=N(L(),{equals:!1}),l=a=>K(a,n());q(()=>{const a=i=>{const r=i.detail?.locale;r&&e(r)};window.addEventListener("taitan:locale-change",a),e(L()),B(()=>window.removeEventListener("taitan:locale-change",a))});const[s,t]=N("0 9 * * 1-5"),o=T(()=>se(s())),u=T(()=>o().ok?le(o(),new Date,10):[]);return(()=>{var a=x(Q),i=a.firstChild,r=i.firstChild,c=r.nextSibling,_=c.nextSibling,[g,p]=y(_.nextSibling),f=i.nextSibling,m=f.firstChild,O=m.nextSibling,[j,F]=y(O.nextSibling),J=f.nextSibling,[D,H]=y(J.nextSibling),P=D.nextSibling;return $(r,()=>l("Cron 表达式（5 段或 6 段含秒）")),c.$$input=v=>t(v.currentTarget.value),$(i,(()=>{var v=I(()=>!!o().ok);return()=>v()?(()=>{var d=x(U);return $(d,()=>o().desc),d})():(()=>{var d=x(V),k=d.firstChild,b=k.nextSibling,[M,w]=y(b.nextSibling);return $(d,()=>o().err,M,w),d})()})(),g,p),$(m,()=>l("预设：")),$(f,()=>oe.map(v=>(()=>{var d=x(X);return d.$$click=()=>t(v.v),$(d,()=>v.k),C(),d})()),j,F),$(a,(()=>{var v=I(()=>!!(o().ok&&u().length>0));return()=>v()&&(()=>{var d=x(Z),k=d.firstChild,b=k.nextSibling,M=b.nextSibling,w=M.firstChild;return $(k,()=>l("未来 10 次触发（本地时区）")),$(b,()=>u().map(R=>A(R)).join(`
`)),w.$$click=()=>G(u().map(A).join(`
`)),$(w,()=>l("复制")),C(),d})()})(),D,H),$(P,()=>l("支持 * / , - / 步长，月/星期可用 Jan-Dec / Sun-Sat 名称。L / W / # 等高级语法暂不支持。")),z(()=>Y(c,"value",s())),C(),a})()}function A(n){const e=l=>String(l).padStart(2,"0");return`${n.getFullYear()}-${e(n.getMonth()+1)}-${e(n.getDate())} ${e(n.getHours())}:${e(n.getMinutes())}:${e(n.getSeconds())} (周${"日一二三四五六"[n.getDay()]})`}W(["input","click"]);export{ce as default};
