profclaw 0.0.1-beta.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -38
- package/CONTRIBUTING.md +3 -5
- package/README.md +128 -63
- package/dist/chat/execution/tools/index.d.ts +1 -1
- package/dist/chat/execution/tools/index.js +41 -2
- package/dist/chat/providers/slack/index.d.ts +2 -2
- package/dist/cli/commands/models.js +39 -26
- package/dist/cli/commands/onboard.js +64 -79
- package/dist/cli/commands/setup.js +293 -90
- package/dist/cli/index.js +0 -6
- package/dist/cli/providers.d.ts +15 -0
- package/dist/cli/providers.js +41 -0
- package/dist/core/deployment.js +2 -0
- package/dist/providers/ai-sdk.js +26 -6
- package/dist/routes/channels.d.ts +12 -0
- package/dist/routes/channels.js +166 -0
- package/dist/server/route-loader.js +1 -0
- package/dist/server.js +115 -109
- package/package.json +1 -1
- package/skills/git-workflow/SKILL.md +3 -3
- package/ui/dist/assets/{ActivityView-DIPQSJ_d.js → ActivityView-BeshZXmE.js} +1 -1
- package/ui/dist/assets/{AgentList-CqyaYrcq.js → AgentList-QVHeldPi.js} +1 -1
- package/ui/dist/assets/{AnalyticsDashboard-C-mjuGHT.js → AnalyticsDashboard-C9R97dXE.js} +1 -1
- package/ui/dist/assets/{AreaChart-CfYWmbtr.js → AreaChart-B73gaiVQ.js} +1 -1
- package/ui/dist/assets/{CartesianChart-BaQ3It0c.js → CartesianChart-CXYL2R-A.js} +1 -1
- package/ui/dist/assets/{ChatView-DxxQy6pl.js → ChatView-qjZErlrp.js} +1 -1
- package/ui/dist/assets/{CostsDashboard-CDBBcGkg.js → CostsDashboard-O4DCLy1i.js} +1 -1
- package/ui/dist/assets/{EstimateSelect-CDjf5qKl.js → EstimateSelect-1hQf4Osk.js} +1 -1
- package/ui/dist/assets/{FloatingChatbot-CZHjvJIe.js → FloatingChatbot-BZBzrJxd.js} +1 -1
- package/ui/dist/assets/{InviteCodeManagement-DTm-IPTm.js → InviteCodeManagement-LEoGqYeA.js} +1 -1
- package/ui/dist/assets/{ProjectDetail-DlYUcOss.js → ProjectDetail--gPfvATB.js} +1 -1
- package/ui/dist/assets/{ProjectIcon-BMRpnM04.js → ProjectIcon-Chd_ofsw.js} +1 -1
- package/ui/dist/assets/{ProjectList-D85TN0i0.js → ProjectList-BvUfVB6c.js} +1 -1
- package/ui/dist/assets/{Settings-CgPqzUvj.js → Settings-1kaf7VHE.js} +1 -1
- package/ui/dist/assets/{StatusIndicator-yig0uZEA.js → StatusIndicator-pRfkNcdV.js} +1 -1
- package/ui/dist/assets/{SummaryDetail-CwLAfHgJ.js → SummaryDetail-DV3AmONk.js} +1 -1
- package/ui/dist/assets/{SummaryList-BvS5Idnu.js → SummaryList-B6kXiTxL.js} +1 -1
- package/ui/dist/assets/{TaskDetail-zarC1fOt.js → TaskDetail-CV6CzbOS.js} +1 -1
- package/ui/dist/assets/{TaskList-CyJq3ANE.js → TaskList-DL7brQKd.js} +1 -1
- package/ui/dist/assets/{TicketBoard-BlWr3-iH.js → TicketBoard-CrkkFj7C.js} +1 -1
- package/ui/dist/assets/{TicketDetail-DmqWKj2W.js → TicketDetail-hnnYclpD.js} +1 -1
- package/ui/dist/assets/{TicketList-Scj4pMWa.js → TicketList-CsDAyQCL.js} +1 -1
- package/ui/dist/assets/{UserManagement-BH7uG7dw.js → UserManagement-BGFQyTSr.js} +1 -1
- package/ui/dist/assets/{ViewSwitcher-3HzZUdWn.js → ViewSwitcher-CnL0OqA8.js} +1 -1
- package/ui/dist/assets/{alert-dialog-DWPb2IfQ.js → alert-dialog-SKM6Gjz4.js} +1 -1
- package/ui/dist/assets/{archive-CGck7gxR.js → archive-BsLa7brF.js} +1 -1
- package/ui/dist/assets/{badge-DEmc3Z_l.js → badge-CVHH1a-v.js} +1 -1
- package/ui/dist/assets/{brain-CfFdLVqb.js → brain-6o_RHVpe.js} +1 -1
- package/ui/dist/assets/{bug-DqSGPUUE.js → bug-CmZI7jqM.js} +1 -1
- package/ui/dist/assets/{calendar-BuZ4zbPW.js → calendar-Bf0t2B82.js} +1 -1
- package/ui/dist/assets/{chevron-up-DcJ4LL_N.js → chevron-up-CoUsOvZj.js} +1 -1
- package/ui/dist/assets/{circle-x-C78PNZjF.js → circle-x-Dgw11LgT.js} +1 -1
- package/ui/dist/assets/{constants-DhDjZe4P.js → constants-Q5Zivl-a.js} +1 -1
- package/ui/dist/assets/{cpu-Ck6AoG8c.js → cpu-DiPMQICV.js} +1 -1
- package/ui/dist/assets/{database-CA2w8Lvt.js → database-BwTfupDi.js} +1 -1
- package/ui/dist/assets/{dialog-BOdGWhgE.js → dialog-BUqN9Psj.js} +1 -1
- package/ui/dist/assets/{ellipsis-FhHKRbfl.js → ellipsis-UJx4Xnf6.js} +1 -1
- package/ui/dist/assets/{ellipsis-vertical-CO0UqE4-.js → ellipsis-vertical-DoULYEKn.js} +1 -1
- package/ui/dist/assets/{file-code-ChnhYYj1.js → file-code-B2UrJLwi.js} +1 -1
- package/ui/dist/assets/{folder-open-CHwA1-ve.js → folder-open-BJi577JH.js} +1 -1
- package/ui/dist/assets/{funnel-ByEjRFNB.js → funnel-PkaD_HSR.js} +1 -1
- package/ui/dist/assets/{git-branch-GTOPQgU4.js → git-branch-C_K30am0.js} +1 -1
- package/ui/dist/assets/{git-commit-horizontal-F5M84Kut.js → git-commit-horizontal-IT6ecxWQ.js} +1 -1
- package/ui/dist/assets/{globe-CQWfr7hT.js → globe-f-jjCa_g.js} +1 -1
- package/ui/dist/assets/{hash-nKC9gtLg.js → hash-DNEv8Elo.js} +1 -1
- package/ui/dist/assets/{history-DfFSA9xJ.js → history-BQSBo_1Q.js} +1 -1
- package/ui/dist/assets/{index-DHGvP9mp.js → index-BUmnwPQr.js} +1 -1
- package/ui/dist/assets/{index-Z4-RtZcs.js → index-BfF5G4Cw.js} +1 -1
- package/ui/dist/assets/{index-DeI8lKRR.js → index-C8N375c2.js} +1 -1
- package/ui/dist/assets/index-CuxnqVVz.css +1 -0
- package/ui/dist/assets/{index-Ca3vk7Gq.js → index-CzMM3QOk.js} +1 -1
- package/ui/dist/assets/{index--JkIxVXb.js → index-lJlNPFVJ.js} +3 -3
- package/ui/dist/assets/{index-a4Fxq0Hb.js → index-nS3EErDg.js} +1 -1
- package/ui/dist/assets/{layers-DFeLExSa.js → layers-jFqVrWMD.js} +1 -1
- package/ui/dist/assets/{layout-dashboard-WmgjMhWF.js → layout-dashboard-CcKt1hXw.js} +1 -1
- package/ui/dist/assets/{lightbulb-Bo8hEr7B.js → lightbulb-Jhp7FvbU.js} +1 -1
- package/ui/dist/assets/{link-2-YqrpQXBH.js → link-2-DdO7ostF.js} +1 -1
- package/ui/dist/assets/{markdown-renderer-Croje6Xe.js → markdown-renderer-n1ToC4XQ.js} +1 -1
- package/ui/dist/assets/{message-square-CD0H5hot.js → message-square-CBgH65X7.js} +1 -1
- package/ui/dist/assets/{pencil-DpFnj5dn.js → pencil-CYXCEPQh.js} +1 -1
- package/ui/dist/assets/{play-DVgea_jT.js → play-d1ONaH0-.js} +1 -1
- package/ui/dist/assets/{popover-JXecfWG5.js → popover-CrmZgoWu.js} +1 -1
- package/ui/dist/assets/{progress-C1ghf1Fu.js → progress-uv4SPkL5.js} +1 -1
- package/ui/dist/assets/{rocket-BFxPYGx9.js → rocket-DhvUetsk.js} +1 -1
- package/ui/dist/assets/{select-MADP8m6Q.js → select-CeQ8AHGy.js} +1 -1
- package/ui/dist/assets/{send-eYnW_7n-.js → send-P0r5D7td.js} +1 -1
- package/ui/dist/assets/{server-CPMaysH8.js → server-CVHTZB72.js} +1 -1
- package/ui/dist/assets/{settings-2-scXUOuE_.js → settings-2-ocj5uHGx.js} +1 -1
- package/ui/dist/assets/{sheet-r6NSOxi-.js → sheet-DuQExSho.js} +1 -1
- package/ui/dist/assets/{shield-check-PEr7nmVw.js → shield-check-DfVdE34l.js} +1 -1
- package/ui/dist/assets/{shield-off-CLtXio62.js → shield-off-8l0J6R-8.js} +1 -1
- package/ui/dist/assets/{skeleton-C9oEzNlU.js → skeleton-TFiFJ3nB.js} +1 -1
- package/ui/dist/assets/{smartphone-DusFfY0U.js → smartphone-77_g3SQn.js} +1 -1
- package/ui/dist/assets/{square-e1yxB2eR.js → square-Ckzsr3Rn.js} +1 -1
- package/ui/dist/assets/{switch-tNs0n-kz.js → switch-CAePkd6k.js} +1 -1
- package/ui/dist/assets/{table-CXxtLicg.js → table-ZjAZ7hkt.js} +1 -1
- package/ui/dist/assets/{tag-tAwMmQ9G.js → tag-C35mgoEv.js} +1 -1
- package/ui/dist/assets/{textarea-BjiEeIWh.js → textarea-DsVPnSgR.js} +1 -1
- package/ui/dist/assets/{timer-Vel1N3RP.js → timer-DHJBS2w1.js} +1 -1
- package/ui/dist/assets/{tooltip-ZMwtfr1J.js → tooltip-BYmQ331W.js} +1 -1
- package/ui/dist/assets/{trash-2-eM-CNwsZ.js → trash-2-keO5tKPE.js} +1 -1
- package/ui/dist/assets/{trending-up-BGafmjRo.js → trending-up-BBv8KbrY.js} +1 -1
- package/ui/dist/assets/{wand-sparkles-DPvcd9Pi.js → wand-sparkles-BusQ52ZK.js} +1 -1
- package/ui/dist/assets/{wrench-B8s3zYVV.js → wrench-02YaOSiK.js} +1 -1
- package/ui/dist/index.html +2 -2
- package/dist/chat/auto-reply.d.ts +0 -90
- package/dist/chat/auto-reply.js +0 -272
- package/dist/chat/execution/pty.d.ts +0 -92
- package/dist/chat/execution/pty.js +0 -285
- package/dist/chat/execution/tools/glinr-ops.d.ts +0 -202
- package/dist/chat/execution/tools/glinr-ops.js +0 -694
- package/dist/cli/commands/browser.d.ts +0 -3
- package/dist/cli/commands/browser.js +0 -138
- package/dist/cli/commands/canvas.d.ts +0 -3
- package/dist/cli/commands/canvas.js +0 -155
- package/dist/cli/commands/nodes.d.ts +0 -3
- package/dist/cli/commands/nodes.js +0 -193
- package/dist/diagnostics/exporters.d.ts +0 -21
- package/dist/diagnostics/exporters.js +0 -138
- package/dist/diagnostics/index.d.ts +0 -10
- package/dist/diagnostics/index.js +0 -9
- package/dist/diagnostics/middleware.d.ts +0 -12
- package/dist/diagnostics/middleware.js +0 -58
- package/dist/diagnostics/tracer.d.ts +0 -133
- package/dist/diagnostics/tracer.js +0 -257
- package/dist/discovery/index.d.ts +0 -8
- package/dist/discovery/index.js +0 -7
- package/dist/discovery/mdns.d.ts +0 -40
- package/dist/discovery/mdns.js +0 -249
- package/dist/plugins/registry.d.ts +0 -122
- package/dist/plugins/registry.js +0 -352
- package/dist/plugins/sandbox.d.ts +0 -77
- package/dist/plugins/sandbox.js +0 -287
- package/dist/plugins/search/brave.d.ts +0 -9
- package/dist/plugins/search/brave.js +0 -157
- package/dist/plugins/search/duckduckgo.d.ts +0 -9
- package/dist/plugins/search/duckduckgo.js +0 -171
- package/dist/plugins/search/index.d.ts +0 -13
- package/dist/plugins/search/index.js +0 -23
- package/dist/plugins/search/searxng.d.ts +0 -9
- package/dist/plugins/search/searxng.js +0 -170
- package/dist/plugins/search/serper.d.ts +0 -9
- package/dist/plugins/search/serper.js +0 -135
- package/dist/plugins/search/tavily.d.ts +0 -9
- package/dist/plugins/search/tavily.js +0 -146
- package/dist/providers/adapters/anthropic.d.ts +0 -26
- package/dist/providers/adapters/anthropic.js +0 -306
- package/dist/providers/adapters/base.d.ts +0 -53
- package/dist/providers/adapters/base.js +0 -99
- package/dist/providers/adapters/ollama.d.ts +0 -30
- package/dist/providers/adapters/ollama.js +0 -292
- package/dist/utils/ai-cache.d.ts +0 -72
- package/dist/utils/ai-cache.js +0 -204
- package/dist/utils/file-lock.d.ts +0 -85
- package/dist/utils/file-lock.js +0 -204
- package/ui/dist/assets/index-WclMPci1.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as le,r,K as ue,C as G,g as J,j as e,i as l,D as Fe,x as Ie,k as D,y as Oe,z,Z as xe,aw as is,R as re,u as Ne,L as ne,U as he,m as O,n as ze,S as qe,a1 as hs,M as ps,ay as gs,o as K,P as fs,O as Ms,l as Rs,p as g,aK as Je,aj as Ds,I as C,v as we,_ as As,be as Ps,A as Fs,X as Is,w as Os}from"./index--JkIxVXb.js";import{A as Js,a as Ls,b as zs,c as qs,d as _s,e as $s,f as Hs,g as Us}from"./alert-dialog-DWPb2IfQ.js";import{M as Ce}from"./message-square-CD0H5hot.js";import{W as Y}from"./wrench-B8s3zYVV.js";import{G as Se}from"./globe-CQWfr7hT.js";import{A as _e}from"./archive-CGck7gxR.js";import{C as ae}from"./circle-x-C78PNZjF.js";import{E as Ks}from"./ellipsis-vertical-CO0UqE4-.js";import{P as Gs}from"./pencil-DpFnj5dn.js";import{H as Qs}from"./history-DfFSA9xJ.js";import{P as ke}from"./play-DVgea_jT.js";import{T as bs}from"./trash-2-eM-CNwsZ.js";import{T as vs}from"./tag-tAwMmQ9G.js";import{T as pe,C as De,I as Le,S as Ws}from"./timer-Vel1N3RP.js";import{D as $e,b as He,c as Ue,d as Ke,a as Bs}from"./dialog-BOdGWhgE.js";import{S as js}from"./settings-2-scXUOuE_.js";import{L as Vs}from"./link-2-YqrpQXBH.js";import{W as Ys}from"./wand-sparkles-DPvcd9Pi.js";import{G as Xs}from"./git-branch-GTOPQgU4.js";import{D as Zs}from"./database-CA2w8Lvt.js";import{F as et}from"./file-code-ChnhYYj1.js";import{C as Te}from"./calendar-BuZ4zbPW.js";import{L as st}from"./lightbulb-Bo8hEr7B.js";import{T as tt}from"./trending-up-BGafmjRo.js";import{F as at}from"./funnel-ByEjRFNB.js";const rt=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]],nt=le("archive-restore",rt);const lt=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],it=le("hard-drive",lt);const ot=[["path",{d:"M11 6a13 13 0 0 0 8.4-2.8A1 1 0 0 1 21 4v12a1 1 0 0 1-1.6.8A13 13 0 0 0 11 14H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z",key:"q8bfy3"}],["path",{d:"M6 14a12 12 0 0 0 2.4 7.2 2 2 0 0 0 3.2-2.4A8 8 0 0 1 10 14",key:"1853fq"}],["path",{d:"M8 6v8",key:"15ugcq"}]],ct=le("megaphone",ot);const dt=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],ge=le("pause",dt);const mt=[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]],os=le("refresh-ccw",mt);const xt=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],ut=le("sliders-horizontal",xt),ht={http:Se,tool:Y,script:ue,message:Ce},pt={active:{color:"text-green-500",bg:"bg-green-500/10",icon:G,label:"Active"},paused:{color:"text-amber-500",bg:"bg-amber-500/10",icon:ge,label:"Paused"},completed:{color:"text-blue-500",bg:"bg-blue-500/10",icon:G,label:"Completed"},failed:{color:"text-red-500",bg:"bg-red-500/10",icon:ae,label:"Failed"},archived:{color:"text-muted-foreground",bg:"bg-muted/50",icon:_e,label:"Archived"}},gt={color:"text-muted-foreground",bg:"bg-muted/50",icon:J,label:"Unknown"};function ft(t){if(!t)return"Not scheduled";const o=new Date(t),f=new Date,i=o.getTime()-f.getTime();return i<0?"Overdue":i<6e4?"In less than a minute":i<36e5?`In ${Math.round(i/6e4)} min`:i<864e5?`In ${Math.round(i/36e5)} hours`:o.toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function bt(t){if(!t)return"Never";const o=new Date(t),i=new Date().getTime()-o.getTime();return i<6e4?"Just now":i<36e5?`${Math.round(i/6e4)} min ago`:i<864e5?`${Math.round(i/36e5)} hours ago`:o.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function vt({job:t,onTrigger:o,onPause:f,onResume:i,onDelete:j,onViewHistory:h,onEdit:N,onArchive:c,onRestore:b}){const[d,m]=r.useState(!1),x=ht[t.jobType]||Y,u=pt[t.status]||gt,P=u.icon,w=t.status==="archived",L=async()=>{m(!0);try{await o(t.id)}finally{m(!1)}},k=t.runCount>0?Math.round(t.successCount/t.runCount*100):0;return e.jsxs("div",{className:"group relative rounded-2xl border border-border/50 bg-card/50 backdrop-blur-sm p-4 hover:border-border hover:shadow-lg transition-all duration-200",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:l("h-10 w-10 rounded-xl flex items-center justify-center shrink-0",u.bg),children:e.jsx(x,{className:l("h-5 w-5",u.color)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm truncate",children:t.name}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:t.description})]})]}),e.jsxs(Fe,{children:[e.jsx(Ie,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 opacity-0 group-hover:opacity-100",children:e.jsx(Ks,{className:"h-4 w-4"})})}),e.jsxs(Oe,{align:"end",className:"w-48",children:[!w&&e.jsxs(e.Fragment,{children:[e.jsxs(z,{onClick:L,disabled:d,children:[e.jsx(xe,{className:"h-4 w-4 mr-2"}),"Run Now"]}),N&&e.jsxs(z,{onClick:()=>N(t),children:[e.jsx(Gs,{className:"h-4 w-4 mr-2"}),"Edit Job"]})]}),e.jsxs(z,{onClick:()=>h(t.id),children:[e.jsx(Qs,{className:"h-4 w-4 mr-2"}),"View History"]}),e.jsx(is,{}),!w&&t.status==="active"&&e.jsxs(z,{onClick:()=>f(t.id),children:[e.jsx(ge,{className:"h-4 w-4 mr-2"}),"Pause Job"]}),!w&&t.status==="paused"&&e.jsxs(z,{onClick:()=>i(t.id),children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Resume Job"]}),w&&b&&e.jsxs(z,{onClick:()=>b(t.id),children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),"Restore Job"]}),e.jsx(is,{}),!w&&c&&e.jsxs(z,{onClick:()=>c(t.id),className:"text-amber-500 focus:text-amber-500",children:[e.jsx(_e,{className:"h-4 w-4 mr-2"}),"Archive Job"]}),e.jsxs(z,{onClick:()=>j(t.id),className:"text-red-500 focus:text-red-500",children:[e.jsx(bs,{className:"h-4 w-4 mr-2"}),"Delete Permanently"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("span",{className:l("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold",u.bg,u.color),children:[e.jsx(P,{className:"h-3 w-3"}),u.label]}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:t.cronExpression||`Every ${Math.round((t.intervalMs||0)/1e3)}s`})]}),t.labels&&t.labels.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mb-3",children:[t.labels.slice(0,3).map(F=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[9px]",children:[e.jsx(vs,{className:"h-2.5 w-2.5"}),F]},F)),t.labels.length>3&&e.jsxs("span",{className:"text-[9px] text-muted-foreground",children:["+",t.labels.length-3]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-3",children:[e.jsxs("div",{className:"text-center p-2 rounded-lg bg-muted/50",children:[e.jsx("div",{className:"text-lg font-bold",children:t.runCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Total Runs"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:l("text-lg font-bold",k>=80?"text-green-500":k>=50?"text-amber-500":"text-red-500"),children:[k,"%"]}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Success"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-muted/50",children:[e.jsx("div",{className:"text-lg font-bold text-red-500",children:t.failureCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Failures"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t border-border/50 pt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:["Last: ",bt(t.lastRunAt)]}),t.lastRunStatus&&e.jsx("span",{className:l("h-1.5 w-1.5 rounded-full",t.lastRunStatus==="success"?"bg-green-500":"bg-red-500")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:ft(t.nextRunAt)})]})]}),e.jsx(D,{variant:"outline",size:"sm",className:"w-full mt-3 h-8 text-xs",onClick:L,disabled:d||t.status==="completed",children:d?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),"Running..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-3.5 w-3.5 mr-1.5"}),"Run Now"]})})]})}const jt={pending:{color:"text-amber-500",bg:"bg-amber-500/10",icon:J,label:"Pending"},running:{color:"text-blue-500",bg:"bg-blue-500/10",icon:ne,label:"Running"},success:{color:"text-green-500",bg:"bg-green-500/10",icon:G,label:"Success"},failure:{color:"text-red-500",bg:"bg-red-500/10",icon:ae,label:"Failed"},error:{color:"text-red-500",bg:"bg-red-500/10",icon:ae,label:"Error"},timeout:{color:"text-orange-500",bg:"bg-orange-500/10",icon:he,label:"Timeout"},cancelled:{color:"text-muted-foreground",bg:"bg-muted/50",icon:ae,label:"Cancelled"}},yt={color:"text-muted-foreground",bg:"bg-muted/50",icon:he,label:"Unknown"};function Nt(t){return t?t<1e3?`${t}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${Math.round(t/6e4)}m ${Math.round(t%6e4/1e3)}s`:"-"}function wt(t){return new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}function kt({jobId:t,jobName:o,open:f,onOpenChange:i}){const{data:j,isLoading:h,error:N,refetch:c}=Ne({queryKey:["cron-history",t],queryFn:()=>O.cron.history(t,50),enabled:!!t&&f,refetchInterval:5e3}),b=j?.history||[],d=j?.job;return e.jsx($e,{open:f,onOpenChange:i,children:e.jsxs(He,{className:"max-w-2xl max-h-[80vh] flex flex-col",children:[e.jsx(Ue,{className:"flex-shrink-0",children:e.jsxs(Ke,{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5 text-primary"}),"Job History: ",o||t?.slice(0,8)]})}),d&&e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-xl bg-muted/50 border border-border/50 mb-4",children:[e.jsxs("div",{className:"flex-1 text-center",children:[e.jsx("div",{className:"text-2xl font-bold",children:d.runCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Total Runs"})]}),e.jsx("div",{className:"h-8 w-px bg-border"}),e.jsxs("div",{className:"flex-1 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-500",children:d.successCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Successes"})]}),e.jsx("div",{className:"h-8 w-px bg-border"}),e.jsxs("div",{className:"flex-1 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-red-500",children:d.failureCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Failures"})]}),e.jsx("div",{className:"h-8 w-px bg-border"}),e.jsxs("div",{className:"flex-1 text-center",children:[e.jsxs("div",{className:"text-2xl font-bold",children:[d.runCount>0?Math.round(d.successCount/d.runCount*100):0,"%"]}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Success Rate"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto -mx-6 px-6",children:h?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(ne,{className:"h-8 w-8 animate-spin text-primary mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading history..."})]}):N?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(he,{className:"h-8 w-8 text-red-500 mb-3"}),e.jsx("p",{className:"text-sm text-red-500",children:"Failed to load history"}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>c(),className:"mt-3",children:[e.jsx(re,{className:"h-4 w-4 mr-2"}),"Retry"]})]}):b.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(J,{className:"h-8 w-8 text-muted-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No runs yet"}),e.jsx("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"History will appear here after the first execution"})]}):e.jsx("div",{className:"space-y-2",children:b.map((m,x)=>{const u=jt[m.status]||yt,P=u.icon,w=m.status==="running";return e.jsxs("div",{className:l("rounded-xl border p-3 transition-colors",x===0?"border-primary/30 bg-primary/5":"border-border/50 bg-card/50"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:l("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold",u.bg,u.color),children:[e.jsx(P,{className:l("h-3 w-3",w&&"animate-spin")}),u.label]}),x===0&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-primary/10 text-primary",children:"Latest"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),Nt(m.durationMs)]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),wt(m.startedAt)]})]})]}),(m.output||m.error)&&e.jsx("div",{className:l("mt-2 p-2 rounded-lg text-xs font-mono overflow-x-auto",m.error?"bg-red-500/10 text-red-400":"bg-muted/50 text-muted-foreground"),children:e.jsx("pre",{className:"whitespace-pre-wrap break-words max-h-32 overflow-y-auto",children:m.error||m.output})})]},m.id)})})}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-border/50 mt-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing ",b.length," runs"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>c(),children:[e.jsx(re,{className:"h-3.5 w-3.5 mr-1.5"}),"Refresh"]})]})]})})}const V=[{id:"type",label:"Type",icon:qe,description:"What kind of job?"},{id:"schedule",label:"Schedule",icon:J,description:"When to run?"},{id:"config",label:"Configure",icon:js,description:"Job details"},{id:"review",label:"Review",icon:hs,description:"Confirm & create"}],cs=[{id:"health-check",name:"Health Check",category:"monitoring",icon:ps,description:"Monitor service health with HTTP pings",jobType:"http",suggestedCron:"*/5 * * * *",payload:{url:"https://your-api.com/health",method:"GET"},guide:"Regularly checks if your service is responding. Great for uptime monitoring."},{id:"db-backup",name:"Database Backup",category:"maintenance",icon:it,description:"Schedule automated database backups",jobType:"script",suggestedCron:"0 2 * * *",payload:{command:"pg_dump",args:["-h","localhost","mydb"]},guide:"Runs daily at 2 AM. Adjust the command for your database type.",warning:"Ensure backup storage has sufficient space."},{id:"git-sync",name:"Git Repository Sync",category:"development",icon:re,description:"Pull latest changes from remote",jobType:"tool",suggestedCron:"*/30 * * * *",payload:{tool:"git_pull",params:{branch:"main"}},guide:"Keeps local repositories in sync with remote."},{id:"slack-standup",name:"Daily Standup Reminder",category:"notifications",icon:ct,description:"Send daily standup reminders to Slack",jobType:"message",suggestedCron:"0 9 * * 1-5",payload:{channel:"#team",message:"Good morning! Time for standup!"},guide:"Sends at 9 AM on weekdays. Change channel and message as needed."},{id:"api-sync",name:"External API Sync",category:"integration",icon:Vs,description:"Sync data from external APIs",jobType:"http",suggestedCron:"0 */4 * * *",payload:{url:"https://api.example.com/sync",method:"POST",headers:{"Content-Type":"application/json"}},guide:"Runs every 4 hours. Add authentication headers if required."},{id:"cleanup",name:"Cleanup Old Files",category:"maintenance",icon:bs,description:"Remove temporary and old files",jobType:"script",suggestedCron:"0 3 * * 0",payload:{command:"find",args:["/tmp","-mtime","+7","-delete"]},guide:"Runs weekly on Sunday at 3 AM.",warning:"Double-check paths before enabling to avoid data loss."},{id:"report-gen",name:"Generate Reports",category:"analytics",icon:gs,description:"Generate and send automated reports",jobType:"tool",suggestedCron:"0 8 * * 1",payload:{tool:"generate_report",params:{type:"weekly",format:"pdf"}},guide:"Generates weekly reports every Monday at 8 AM."},{id:"webhook-trigger",name:"Webhook Trigger",category:"integration",icon:xe,description:"Trigger external webhooks on schedule",jobType:"http",suggestedCron:"0 */6 * * *",payload:{url:"https://hooks.example.com/trigger",method:"POST",body:{event:"scheduled"}},guide:"Triggers every 6 hours. Customize the webhook URL and payload."}],Ct=[{id:"all",label:"All",icon:qe},{id:"monitoring",label:"Monitoring",icon:hs},{id:"maintenance",label:"Maintenance",icon:Y},{id:"development",label:"Development",icon:Xs},{id:"notifications",label:"Notifications",icon:Je},{id:"integration",label:"Integration",icon:Ds},{id:"analytics",label:"Analytics",icon:Zs}],te=[{type:"http",label:"HTTP Request",icon:Se,description:"Call an API endpoint",color:"from-blue-500/20 to-cyan-500/20",examples:["Sync data from API","Health checks","Webhook triggers"],defaultPayload:{url:"https://api.example.com/endpoint",method:"POST",headers:{}},guide:"Make HTTP requests to external services. Supports GET, POST, PUT, DELETE methods."},{type:"tool",label:"Tool Execution",icon:Y,description:"Run a profClaw tool",color:"from-indigo-500/20 to-pink-500/20",examples:["Git operations","File sync","Database backups"],defaultPayload:{tool:"git_status",params:{}},guide:"Execute any registered profClaw tool with custom parameters."},{type:"script",label:"Shell Script",icon:ue,description:"Execute a command",color:"from-green-500/20 to-emerald-500/20",examples:["Build scripts","Cleanup tasks","System checks"],defaultPayload:{command:'echo "Hello World"',args:[]},guide:"Run shell commands on the server. Use with caution.",warning:"Scripts run with server permissions. Avoid sensitive operations."},{type:"message",label:"Notification",icon:Ce,description:"Send a message",color:"from-orange-500/20 to-amber-500/20",examples:["Daily standup reminder","Status reports","Alerts"],defaultPayload:{channel:"#general",message:"Scheduled notification"},guide:"Send messages to Slack channels, email, or webhooks."}],St=[{type:"cron",label:"Cron",icon:J,description:"Classic cron syntax"},{type:"interval",label:"Interval",icon:pe,description:"Every X seconds"},{type:"oneshot",label:"One-Time",icon:Te,description:"Run once"},{type:"event",label:"Event",icon:xe,description:"On trigger"}],ys=[{label:"Every minute",value:"* * * * *",humanize:"Runs every minute"},{label:"Every 5 min",value:"*/5 * * * *",humanize:"Runs every 5 minutes"},{label:"Every 15 min",value:"*/15 * * * *",humanize:"Runs every 15 minutes"},{label:"Hourly",value:"0 * * * *",humanize:"Runs at the start of every hour"},{label:"Daily midnight",value:"0 0 * * *",humanize:"Runs daily at midnight"},{label:"Weekdays 9am",value:"0 9 * * 1-5",humanize:"Runs at 9am on weekdays"}],Ae=[{label:"30 sec",value:30,humanize:"Every 30 seconds"},{label:"1 min",value:60,humanize:"Every minute"},{label:"5 min",value:300,humanize:"Every 5 minutes"},{label:"15 min",value:900,humanize:"Every 15 minutes"},{label:"30 min",value:1800,humanize:"Every 30 minutes"},{label:"1 hour",value:3600,humanize:"Every hour"}],Tt=[{type:"webhook",label:"Webhook",description:"HTTP webhook endpoint"},{type:"ticket",label:"Ticket",description:"Ticket changes"},{type:"github",label:"GitHub",description:"Push, PR, issues"},{type:"file",label:"File",description:"File changes"}];function _({children:t,type:o="info"}){const f={info:"bg-blue-500/10 border-blue-500/20 text-blue-700 dark:text-blue-300",warning:"bg-amber-500/10 border-amber-500/20 text-amber-700 dark:text-amber-300",tip:"bg-green-500/10 border-green-500/20 text-green-700 dark:text-green-300"},j={info:Le,warning:he,tip:st}[o];return e.jsxs("div",{className:l("flex items-start gap-2 p-3 rounded-lg border text-xs",f[o]),children:[e.jsx(j,{className:"h-4 w-4 shrink-0 mt-0.5"}),e.jsx("div",{children:t})]})}function Pe({children:t,content:o}){return e.jsxs("span",{className:"relative group",children:[t,e.jsx("span",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 rounded bg-popover border text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-50",children:o})]})}function ds(t){const o=ys.find(b=>b.value===t);if(o)return o.humanize;const f=t.split(" ");if(f.length!==5)return`Cron: ${t}`;const[i,j,h,N,c]=f;return i.startsWith("*/")&&j==="*"&&h==="*"&&N==="*"&&c==="*"?`Every ${i.slice(2)} minutes`:i==="0"&&j.startsWith("*/")&&h==="*"&&N==="*"&&c==="*"?`Every ${j.slice(2)} hours`:i==="0"&&j==="0"&&h==="*"&&N==="*"&&c==="*"?"Daily at midnight":`Cron: ${t}`}function Et(t){try{return{valid:!0,parsed:JSON.parse(t)}}catch{return{valid:!1,error:"Invalid JSON syntax"}}}function ms({open:t,onOpenChange:o}){const f=ze(),[i,j]=r.useState(!1),h=t??i,N=o??j,[c,b]=r.useState("simple"),[d,m]=r.useState("type"),x=V.findIndex(s=>s.id===d),[u,P]=r.useState("all"),[w,L]=r.useState(""),[k,F]=r.useState(""),[p,$]=r.useState(null),[v,E]=r.useState(null),[M,q]=r.useState("*/5 * * * *"),[A,H]=r.useState(300),[T,n]=r.useState(""),[R,fe]=r.useState(""),[U,be]=r.useState("webhook"),[ve,je]=r.useState("{}"),[Q,X]=r.useState("{}"),[I,Z]=r.useState(null),[a,ee]=r.useState("UTC"),[ie,Ge]=r.useState(!0),[Ee,Qe]=r.useState(3),[Me,We]=r.useState("exponential"),[oe,Be]=r.useState(!1),[W,Ve]=r.useState(""),[Ye,Xe]=r.useState(!1),[Ze,es]=r.useState(!0),[ss,ts]=r.useState(!1),[ce,as]=r.useState(null),[Re,rs]=r.useState(null),de=r.useMemo(()=>Et(Q),[Q]),{data:Ns}=Ne({queryKey:["cron-templates"],queryFn:()=>O.cron.listTemplates?.()||Promise.resolve({templates:[]}),enabled:h}),ns=Ns?.templates||[],ws=r.useMemo(()=>u==="all"?cs:cs.filter(s=>s.category===u),[u]);r.useEffect(()=>{if(p&&!I){const s=te.find(y=>y.type===p);s&&X(JSON.stringify(s.defaultPayload,null,2))}},[p,I]);const ls=s=>{if(I?.id===s.id){Z(null);return}Z(s),L(s.name),F(s.description??""),$(s.jobType),X(JSON.stringify(s.payload,null,2)),s.suggestedCron&&(E("cron"),q(s.suggestedCron))},se=K({mutationFn:()=>{const s=JSON.parse(Q);let y;v==="oneshot"&&T&&R&&(y=new Date(`${T}T${R}`).toISOString());let S;if(v==="event")try{S={type:U,config:JSON.parse(ve)}}catch{S={type:U,config:{}}}let B;return c==="advanced"&&oe&&W&&(B={channels:[{type:W.includes("@")?"email":W.startsWith("http")?"webhook":"slack",target:W,onSuccess:Ye,onFailure:Ze}]}),O.cron.create({name:w,description:k||void 0,jobType:p,cronExpression:v==="cron"?M:void 0,intervalMs:v==="interval"?A*1e3:void 0,runAt:y,eventTrigger:S,payload:s,timezone:c==="advanced"?a:"UTC",deleteOnComplete:v==="oneshot"?ss:void 0,retryPolicy:c==="advanced"?{enabled:ie,maxRetries:Ee,backoff:Me}:void 0,delivery:B,maxRuns:c==="advanced"&&ce||void 0,maxFailures:c==="advanced"&&Re||void 0})},onSuccess:()=>{f.invalidateQueries({queryKey:["cron-jobs"]}),f.invalidateQueries({queryKey:["cron-stats"]}),N(!1),ks()}}),ks=()=>{m("type"),b("simple"),P("all"),L(""),F(""),$(null),E(null),q("*/5 * * * *"),H(300),n(""),fe(""),be("webhook"),je("{}"),X("{}"),Z(null),ee("UTC"),Ge(!0),Qe(3),We("exponential"),Be(!1),Ve(""),Xe(!1),es(!0),ts(!1),as(null),rs(null)},Cs=r.useMemo(()=>{switch(d){case"type":return p!==null;case"schedule":return v?v==="oneshot"?T&&R:!0:!1;case"config":return w.trim().length>0&&de.valid;case"review":return!0;default:return!1}},[d,p,v,T,R,w,de]),Ss=()=>{x<V.length-1&&m(V[x+1].id)},Ts=()=>{x>0&&m(V[x-1].id)},Es=r.useMemo(()=>{switch(v){case"cron":return ds(M);case"interval":return Ae.find(s=>s.value===A)?.humanize||`Every ${A} seconds`;case"oneshot":return T&&R?`Once at ${new Date(`${T}T${R}`).toLocaleString()}`:"One-time (not scheduled)";case"event":return`On ${U} event`;default:return"Not configured"}},[v,M,A,T,R,U]),ye=te.find(s=>s.type===p);return e.jsxs($e,{open:h,onOpenChange:N,children:[e.jsx(Bs,{asChild:!0,children:e.jsxs(D,{className:"gap-2 shadow-lg shadow-primary/20 hover:shadow-primary/30 transition-shadow",children:[e.jsx(fs,{className:"h-4 w-4"}),"Create Job"]})}),e.jsxs(He,{className:"max-w-4xl w-[90vw] max-h-[85vh] my-8 flex flex-col p-0 overflow-hidden [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",children:[e.jsxs("div",{className:"border-b border-border/20 bg-linear-to-r from-primary/5 to-transparent",children:[e.jsx(Ue,{className:"px-6 pt-5 pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Ke,{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(J,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"block",children:"Create Scheduled Job"}),e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:V[x].description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 p-1 rounded-lg bg-muted",children:[e.jsxs("button",{onClick:()=>b("simple"),className:l("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-all",c==="simple"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(Ys,{className:"h-3 w-3"}),"Simple"]}),e.jsxs("button",{onClick:()=>b("advanced"),className:l("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-all",c==="advanced"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(ut,{className:"h-3 w-3"}),"Advanced"]})]})]})}),e.jsx("div",{className:"px-6 pb-4",children:e.jsx("div",{className:"flex items-center gap-2",children:V.map((s,y)=>{const S=s.icon,B=s.id===d,me=y<x;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>y<=x&&m(s.id),disabled:y>x,className:l("flex items-center gap-2 px-3 py-1.5 rounded-full text-xs font-medium transition-all",B&&"bg-primary text-primary-foreground shadow-md shadow-primary/30",me&&"bg-primary/20 text-primary hover:bg-primary/30",!B&&!me&&"bg-muted text-muted-foreground",y>x&&"opacity-50 cursor-not-allowed"),children:[me?e.jsx(Ms,{className:"h-3 w-3"}):e.jsx(S,{className:"h-3 w-3"}),e.jsx("span",{className:"hidden sm:inline",children:s.label})]}),y<V.length-1&&e.jsx(Rs,{className:l("h-4 w-4",y<x?"text-primary":"text-muted-foreground/50")})]},s.id)})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",children:[d==="type"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[c==="simple"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Quick Start Templates"}),e.jsx(Pe,{content:"Pre-configured jobs for common tasks",children:e.jsx(De,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"})})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:Ct.map(s=>{const y=s.icon,S=u===s.id;return e.jsxs("button",{onClick:()=>P(s.id),className:l("flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-medium transition-all",S?"bg-foreground text-background shadow-sm":"bg-muted text-muted-foreground hover:bg-muted/80"),children:[e.jsx(y,{className:"h-3 w-3"}),s.label]},s.id)})}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ws.map(s=>{const y=s.icon;return e.jsxs("button",{onClick:()=>ls(s),className:l("flex items-start gap-3 p-3 rounded-xl text-left transition-all hover:scale-[1.01]",I?.id===s.id?"bg-primary/5 ring-2 ring-primary/20":"bg-muted/30 hover:bg-muted/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-lg shrink-0",I?.id===s.id?"bg-primary/20 text-primary":"bg-muted text-muted-foreground"),children:e.jsx(y,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsx("div",{className:"text-[10px] text-muted-foreground line-clamp-2",children:s.description})]})]},s.id)})}),ns.length>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t",children:[e.jsx(g,{className:"text-xs text-muted-foreground",children:"Your Templates"}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:ns.slice(0,4).map(s=>e.jsxs("button",{onClick:()=>ls({id:s.id,name:s.name,category:s.category,description:s.description,jobType:s.jobType,payload:s.payloadTemplate,suggestedCron:s.suggestedCron}),className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-muted/30 hover:bg-muted/50 text-xs",children:[e.jsx(et,{className:"h-3 w-3 text-primary"}),s.name]},s.id))})]}),e.jsx("div",{className:"mt-4",children:e.jsx(_,{type:"tip",children:"Select a template to get started quickly, or choose a job type below for custom configuration."})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:c==="simple"?"Or Choose Job Type":"Job Type"})}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:te.map(s=>{const y=s.icon,S=p===s.type;return e.jsxs("button",{onClick:()=>{$(s.type),Z(null)},className:l("relative overflow-hidden group p-4 rounded-2xl text-left transition-all duration-200",S?"bg-primary/5 ring-2 ring-primary/20 scale-[1.02]":"bg-muted/30 hover:bg-muted/50 hover:scale-[1.01]"),children:[e.jsx("div",{className:l("absolute inset-0 bg-linear-to-br opacity-0 transition-opacity",s.color,S&&"opacity-100","group-hover:opacity-50")}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:l("p-2 rounded-lg transition-colors",S?"bg-primary text-primary-foreground":"bg-muted"),children:e.jsx(y,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:l("font-semibold",S&&"text-primary"),children:s.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.description})]}),S&&e.jsx(G,{className:"h-5 w-5 text-primary"})]}),c==="advanced"&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-3",children:s.examples.map((B,me)=>e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-muted/80 text-[10px] text-muted-foreground",children:B},me))})]})]},s.type)})}),ye&&e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx(_,{type:"info",children:ye.guide}),ye.warning&&e.jsx(_,{type:"warning",children:ye.warning})]})]})]}),d==="schedule"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"When to Run?"}),e.jsx("div",{className:"grid grid-cols-4 gap-2 mt-3",children:St.map(s=>{const y=s.icon,S=v===s.type;return e.jsxs("button",{onClick:()=>E(s.type),className:l("flex flex-col items-center gap-2 p-4 rounded-xl transition-all",S?"bg-primary/5 ring-2 ring-primary/20":"bg-muted/30 hover:bg-muted/50"),children:[e.jsx(y,{className:l("h-6 w-6",S?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:l("text-xs font-medium",S&&"text-primary"),children:s.label})]},s.type)})})]}),v==="cron"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"cron",children:"Cron Expression"}),e.jsx(C,{id:"cron",placeholder:"*/5 * * * *",value:M,onChange:s=>q(s.target.value),className:"mt-2 font-mono text-sm"}),e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(ke,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:ds(M)})]})})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs text-muted-foreground",children:"Presets"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:ys.map(s=>e.jsx("button",{onClick:()=>q(s.value),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",M===s.value?"bg-primary text-primary-foreground shadow-md":"bg-muted hover:bg-muted/80"),children:s.label},s.value))})]}),e.jsxs(_,{type:"info",children:["Cron format: ",e.jsx("code",{className:"font-mono bg-muted px-1 rounded",children:"minute hour day month weekday"}),e.jsx("br",{}),"Use ",e.jsx("code",{className:"font-mono bg-muted px-1 rounded",children:"*"})," for any value, ",e.jsx("code",{className:"font-mono bg-muted px-1 rounded",children:"*/N"})," for every N units."]})]}),v==="interval"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"interval",children:"Interval (seconds)"}),e.jsx(C,{id:"interval",type:"number",min:1,value:A,onChange:s=>H(parseInt(s.target.value)||60),className:"mt-2"}),e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(pe,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:Ae.find(s=>s.value===A)?.humanize||`Every ${A} seconds`})]})})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ae.map(s=>e.jsx("button",{onClick:()=>H(s.value),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",A===s.value?"bg-primary text-primary-foreground shadow-md":"bg-muted hover:bg-muted/80"),children:s.label},s.value))})]}),v==="oneshot"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Run At"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mt-2",children:[e.jsxs("div",{children:[e.jsx(C,{type:"date",value:T,onChange:s=>n(s.target.value),min:new Date().toISOString().split("T")[0]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Date"})]}),e.jsxs("div",{children:[e.jsx(C,{type:"time",value:R,onChange:s=>fe(s.target.value)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Time"})]})]}),T&&R&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:new Date(`${T}T${R}`).toLocaleString()})]})})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ss,onChange:s=>ts(s.target.checked),className:"rounded"}),e.jsx("span",{className:"text-muted-foreground",children:"Auto-delete after completion"})]}),e.jsx(_,{type:"info",children:"One-shot jobs run exactly once at the specified time and can optionally be deleted afterward."})]}),v==="event"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Event Type"}),e.jsx("div",{className:"grid grid-cols-4 gap-2 mt-2",children:Tt.map(s=>e.jsxs("button",{onClick:()=>be(s.type),className:l("flex flex-col items-center p-3 rounded-xl text-center transition-all",U===s.type?"bg-primary/5 ring-2 ring-primary/20":"bg-muted/30 hover:bg-muted/50"),children:[e.jsx("span",{className:l("text-xs font-medium",U===s.type&&"text-primary"),children:s.label}),e.jsx("span",{className:"text-[9px] text-muted-foreground mt-0.5",children:s.description})]},s.type))})]}),c==="advanced"&&e.jsxs("div",{children:[e.jsx(g,{htmlFor:"eventConfig",children:"Event Config (JSON)"}),e.jsx(C,{id:"eventConfig",placeholder:'{"source": "webhook"}',value:ve,onChange:s=>je(s.target.value),className:"mt-2 font-mono text-xs"})]}),e.jsx(_,{type:"info",children:"Event-triggered jobs run when specific events occur, like webhooks or file changes."})]}),c==="advanced"&&v==="cron"&&e.jsxs("div",{children:[e.jsx(g,{htmlFor:"timezone",children:"Timezone"}),e.jsx(C,{id:"timezone",placeholder:"UTC",value:a,onChange:s=>ee(s.target.value),className:"mt-2"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Default: UTC. Use IANA timezone names (e.g., America/New_York)."})]})]}),d==="config"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[I?.guide&&e.jsxs(_,{type:"tip",children:[e.jsxs("strong",{children:[I.name,":"]})," ",I.guide]}),I?.warning&&e.jsx(_,{type:"warning",children:I.warning}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"name",className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Job Name *"}),e.jsx(C,{id:"name",placeholder:"e.g., Sync GitHub Issues",value:w,onChange:s=>L(s.target.value),className:"mt-2 text-lg font-medium"})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"description",className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Description"}),e.jsx(C,{id:"description",placeholder:"What this job does...",value:k,onChange:s=>F(s.target.value),className:"mt-2"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(g,{htmlFor:"payload",className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Payload (JSON)"}),de.valid?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-600",children:[e.jsx(G,{className:"h-3 w-3"})," Valid"]}):e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[e.jsx(we,{className:"h-3 w-3"})," ",de.error]})]}),e.jsx("textarea",{id:"payload",value:Q,onChange:s=>X(s.target.value),className:l("w-full p-4 rounded-xl bg-muted/40 font-mono text-sm resize-none h-32 transition-colors focus:outline-none focus:ring-1 focus:ring-primary/30",!de.valid&&"ring-1 ring-red-500"),placeholder:'{"url": "https://..."}'})]}),c==="advanced"&&e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 space-y-4",children:[e.jsxs("div",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2",children:[e.jsx(js,{className:"h-3.5 w-3.5"}),"Advanced Options"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(os,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:"Retry on failure"})]}),e.jsx("input",{type:"checkbox",checked:ie,onChange:s=>Ge(s.target.checked),className:"rounded"})]}),ie&&e.jsxs("div",{className:"grid grid-cols-2 gap-3 pl-6",children:[e.jsxs("div",{children:[e.jsx(g,{className:"text-xs",children:"Max Retries"}),e.jsx(C,{type:"number",min:1,max:10,value:Ee,onChange:s=>Qe(parseInt(s.target.value)||3),className:"mt-1 h-8 text-xs"})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs",children:"Backoff"}),e.jsxs("select",{value:Me,onChange:s=>We(s.target.value),className:"w-full mt-1 h-8 px-2 rounded-md border bg-background text-xs",children:[e.jsx("option",{value:"exponential",children:"Exponential"}),e.jsx("option",{value:"linear",children:"Linear"}),e.jsx("option",{value:"fixed",children:"Fixed"})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:"Send notifications"})]}),e.jsx("input",{type:"checkbox",checked:oe,onChange:s=>Be(s.target.checked),className:"rounded"})]}),oe&&e.jsxs("div",{className:"pl-6 space-y-2",children:[e.jsx(C,{placeholder:"Slack channel, webhook URL, or email",value:W,onChange:s=>Ve(s.target.value),className:"text-xs"}),e.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"checkbox",checked:Ye,onChange:s=>Xe(s.target.checked),className:"rounded"}),"On success"]}),e.jsxs("label",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"checkbox",checked:Ze,onChange:s=>es(s.target.checked),className:"rounded"}),"On failure"]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs(g,{className:"text-xs flex items-center gap-1",children:["Max Runs",e.jsx(Pe,{content:"Stop after N runs",children:e.jsx(De,{className:"h-3 w-3"})})]}),e.jsx(C,{type:"number",min:1,placeholder:"Unlimited",value:ce||"",onChange:s=>as(s.target.value?parseInt(s.target.value):null),className:"mt-1 h-8 text-xs"})]}),e.jsxs("div",{children:[e.jsxs(g,{className:"text-xs flex items-center gap-1",children:["Max Failures",e.jsx(Pe,{content:"Pause after N consecutive failures",children:e.jsx(De,{className:"h-3 w-3"})})]}),e.jsx(C,{type:"number",min:1,placeholder:"Unlimited",value:Re||"",onChange:s=>rs(s.target.value?parseInt(s.target.value):null),className:"mt-1 h-8 text-xs"})]})]})]})]}),d==="review"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-linear-to-br from-primary/20 to-primary/5 mb-3",children:e.jsx(G,{className:"h-8 w-8 text-primary"})}),e.jsx("h3",{className:"text-lg font-semibold",children:"Ready to Create"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Review your job configuration"})]}),e.jsxs("div",{className:"p-5 rounded-2xl bg-linear-to-br from-muted/50 to-transparent space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Job Name"}),e.jsx("div",{className:"text-lg font-semibold mt-1",children:w||"Untitled Job"}),k&&e.jsx("div",{className:"text-sm text-muted-foreground mt-0.5",children:k})]}),p&&e.jsx("div",{className:l("p-2 rounded-lg",p==="http"&&"bg-blue-500/20",p==="tool"&&"bg-indigo-500/20",p==="script"&&"bg-green-500/20",p==="message"&&"bg-orange-500/20"),children:te.find(s=>s.type===p)?.icon&&(()=>{const s=te.find(y=>y.type===p).icon;return e.jsx(s,{className:"h-5 w-5"})})()})]}),e.jsx("hr",{className:"border-border/50"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Type"}),e.jsx("div",{className:"text-sm font-medium mt-1",children:te.find(s=>s.type===p)?.label})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Schedule"}),e.jsx("div",{className:"text-sm font-medium mt-1",children:Es})]})]}),e.jsx("hr",{className:"border-border/50"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-2",children:"Payload"}),e.jsx("pre",{className:"p-3 rounded-lg bg-muted/50 text-xs font-mono overflow-x-auto max-h-24",children:Q})]}),c==="advanced"&&(ie||oe||ce||Re)&&e.jsxs(e.Fragment,{children:[e.jsx("hr",{className:"border-border/50"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ie&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-muted text-xs",children:[e.jsx(os,{className:"h-3 w-3"}),Ee,"x ",Me," retries"]}),oe&&W&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-muted text-xs",children:[e.jsx(Je,{className:"h-3 w-3"}),"Notify: ",W.slice(0,15),"..."]}),ce&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-muted text-xs",children:[e.jsx(As,{className:"h-3 w-3"}),"Max ",ce," runs"]})]})]})]}),p==="script"&&e.jsxs(_,{type:"warning",children:[e.jsx("strong",{children:"Security Notice:"})," Script jobs execute shell commands with server permissions. Ensure your command is safe before creating."]}),se.isError&&e.jsxs("div",{className:"flex items-center gap-2 p-4 rounded-xl bg-red-500/10 border border-red-500/20 text-red-500 text-sm",children:[e.jsx(we,{className:"h-5 w-5 shrink-0"}),e.jsx("span",{children:se.error instanceof Error?se.error.message:"Failed to create job"})]})]})]}),e.jsxs("div",{className:"border-t border-border/20 p-4 flex items-center justify-between bg-muted/30",children:[e.jsxs(D,{variant:"ghost",onClick:x===0?()=>N(!1):Ts,className:"gap-2",children:[e.jsx(Ps,{className:"h-4 w-4"}),x===0?"Cancel":"Back"]}),d==="review"?e.jsx(D,{onClick:()=>se.mutate(),disabled:se.isPending,className:"gap-2 min-w-35 shadow-lg shadow-primary/20",children:se.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qe,{className:"h-4 w-4"}),"Create Job"]})}):e.jsxs(D,{onClick:Ss,disabled:!Cs,className:"gap-2",children:["Continue",e.jsx(Fs,{className:"h-4 w-4"})]})]})]})]})}const Mt=[{value:"http",label:"HTTP Request",icon:Se},{value:"tool",label:"Tool Execution",icon:Y},{value:"script",label:"Shell Script",icon:ue},{value:"message",label:"Notification",icon:Ce}],Rt=[{label:"1 min",value:"* * * * *"},{label:"5 min",value:"*/5 * * * *"},{label:"15 min",value:"*/15 * * * *"},{label:"30 min",value:"*/30 * * * *"},{label:"Hourly",value:"0 * * * *"},{label:"Daily",value:"0 0 * * *"},{label:"Weekly",value:"0 0 * * 0"}];function Dt(t){return{"* * * * *":"Every minute","*/5 * * * *":"Every 5 minutes","*/15 * * * *":"Every 15 minutes","*/30 * * * *":"Every 30 minutes","0 * * * *":"Every hour","0 0 * * *":"Daily at midnight","0 0 * * 0":"Weekly on Sunday","0 9 * * 1-5":"Weekdays at 9 AM"}[t]||t}function At({type:t,children:o}){const f={info:{icon:Le,bg:"bg-blue-500/10",border:"border-blue-500/20",text:"text-blue-400"},warning:{icon:we,bg:"bg-amber-500/10",border:"border-amber-500/20",text:"text-amber-400"},tip:{icon:Le,bg:"bg-green-500/10",border:"border-green-500/20",text:"text-green-400"}},{icon:i,bg:j,border:h,text:N}=f[t];return e.jsxs("div",{className:l("flex items-start gap-2 p-3 rounded-lg border text-xs",j,h,N),children:[e.jsx(i,{className:"h-4 w-4 shrink-0 mt-0.5"}),e.jsx("div",{children:o})]})}function Pt({job:t,open:o,onOpenChange:f}){const i=ze(),[j,h]=r.useState(""),[N,c]=r.useState(""),[b,d]=r.useState("cron"),[m,x]=r.useState("*/5 * * * *"),[u,P]=r.useState(300),[w,L]=r.useState("{}"),[k,F]=r.useState([]),[p,$]=r.useState(""),[v,E]=r.useState("active");r.useEffect(()=>{t&&(h(t.name),c(t.description||""),d(t.cronExpression?"cron":"interval"),x(t.cronExpression||"*/5 * * * *"),P(t.intervalMs?Math.round(t.intervalMs/1e3):300),L(JSON.stringify(t.payload||{},null,2)),F(t.labels||[]),E(t.status==="paused"?"paused":"active"))},[t]);const M=K({mutationFn:()=>{if(!t)throw new Error("No job to update");const n=JSON.parse(w);return O.cron.update(t.id,{name:j,description:N||void 0,cronExpression:b==="cron"?m:void 0,intervalMs:b==="interval"?u*1e3:void 0,payload:n,labels:k,status:v})},onSuccess:()=>{i.invalidateQueries({queryKey:["cron-jobs"]}),i.invalidateQueries({queryKey:["cron-stats"]}),f(!1)}}),q=j.trim().length>0&&(b==="cron"&&m.trim().length>0||b==="interval"&&u>=1),A=()=>{const n=p.trim().toLowerCase();n&&!k.includes(n)&&(F([...k,n]),$(""))},H=n=>{F(k.filter(R=>R!==n))};if(!t)return null;const T=Mt.find(n=>n.value===t.jobType)?.icon||Y;return e.jsx($e,{open:o,onOpenChange:f,children:e.jsxs(He,{className:"max-w-2xl max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsx(Ue,{children:e.jsxs(Ke,{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(T,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"block",children:"Edit Scheduled Job"}),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:[t.jobType.toUpperCase()," • Created ",new Date(t.createdAt).toLocaleDateString()]})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"name",children:"Job Name"}),e.jsx(C,{id:"name",value:j,onChange:n=>h(n.target.value),placeholder:"My Scheduled Job",className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"description",children:"Description (optional)"}),e.jsx(C,{id:"description",value:N,onChange:n=>c(n.target.value),placeholder:"What this job does...",className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2 block",children:"Status"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>E("active"),className:l("flex items-center gap-2 px-4 py-2 rounded-xl border transition-all",v==="active"?"border-green-500/50 bg-green-500/10 text-green-500":"border-border/50 hover:border-border"),children:[e.jsx(ke,{className:"h-4 w-4"}),"Active"]}),e.jsxs("button",{onClick:()=>E("paused"),className:l("flex items-center gap-2 px-4 py-2 rounded-xl border transition-all",v==="paused"?"border-amber-500/50 bg-amber-500/10 text-amber-500":"border-border/50 hover:border-border"),children:[e.jsx(ge,{className:"h-4 w-4"}),"Paused"]})]})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2 block",children:"Schedule"}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsxs("button",{onClick:()=>d("cron"),className:l("flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-all",b==="cron"?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:[e.jsx(J,{className:"h-4 w-4"}),"Cron"]}),e.jsxs("button",{onClick:()=>d("interval"),className:l("flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-all",b==="interval"?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:[e.jsx(pe,{className:"h-4 w-4"}),"Interval"]})]}),b==="cron"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(C,{value:m,onChange:n=>x(n.target.value),placeholder:"*/5 * * * *",className:"font-mono"}),e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(ke,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:Dt(m)})]})})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Rt.map(n=>e.jsx("button",{onClick:()=>x(n.value),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",m===n.value?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:n.label},n.value))})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Every"}),e.jsx(C,{type:"number",min:1,value:u,onChange:n=>P(parseInt(n.target.value)||60),className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"seconds"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[30,60,300,600,1800,3600].map(n=>e.jsx("button",{onClick:()=>P(n),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",u===n?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:n<60?`${n}s`:n<3600?`${n/60}m`:`${n/3600}h`},n))})]})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2 block",children:"Labels"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:k.map(n=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-lg bg-primary/10 text-primary text-xs",children:[e.jsx(vs,{className:"h-3 w-3"}),n,e.jsx("button",{onClick:()=>H(n),className:"ml-1 hover:text-red-500",children:e.jsx(Is,{className:"h-3 w-3"})})]},n))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{value:p,onChange:n=>$(n.target.value),placeholder:"Add label...",className:"flex-1",onKeyDown:n=>n.key==="Enter"&&(n.preventDefault(),A())}),e.jsx(D,{variant:"outline",size:"sm",onClick:A,disabled:!p.trim(),children:e.jsx(fs,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"payload",children:"Payload (JSON)"}),e.jsx("textarea",{id:"payload",value:w,onChange:n=>L(n.target.value),rows:6,className:"w-full mt-1.5 px-3 py-2 rounded-lg border border-border bg-background font-mono text-sm resize-none focus:outline-none focus:ring-2 focus:ring-primary/50"}),e.jsx(At,{type:"info",children:"Payload is specific to job type. HTTP jobs need url/method, tool jobs need tool/params."})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsx(D,{variant:"ghost",onClick:()=>f(!1),children:"Cancel"}),e.jsx(D,{onClick:()=>M.mutate(),disabled:!q||M.isPending,className:"gap-2",children:M.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ws,{className:"h-4 w-4"}),"Save Changes"]})})]}),M.isError&&e.jsxs("div",{className:"mt-2 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm",children:[e.jsx(we,{className:"h-4 w-4 inline mr-2"}),M.error.message]})]})})}const xs=[{value:"all",label:"All Status",icon:J},{value:"active",label:"Active",icon:G},{value:"paused",label:"Paused",icon:ge},{value:"completed",label:"Completed",icon:G},{value:"failed",label:"Failed",icon:ae},{value:"archived",label:"Archived",icon:_e}],us=[{value:"all",label:"All Types",icon:Te},{value:"http",label:"HTTP",icon:Se},{value:"tool",label:"Tool",icon:Y},{value:"script",label:"Script",icon:ue},{value:"message",label:"Message",icon:Ce}];function na(){const t=ze(),[o,f]=r.useState(""),[i,j]=r.useState("all"),[h,N]=r.useState("all"),[c,b]=r.useState(null),[d,m]=r.useState(""),[x,u]=r.useState(null),[P,w]=r.useState(null),{data:L,isLoading:k,error:F,refetch:p}=Ne({queryKey:["cron-jobs",i,h],queryFn:()=>O.cron.list({status:i!=="all"?i:void 0,jobType:h!=="all"?h:void 0,limit:100}),refetchInterval:1e4}),{data:$}=Ne({queryKey:["cron-stats"],queryFn:()=>O.cron.stats(),refetchInterval:3e4}),v=L?.jobs||[],E=$?.stats,M=v.filter(a=>o?a.name.toLowerCase().includes(o.toLowerCase())||a.description?.toLowerCase().includes(o.toLowerCase()):!0),q=K({mutationFn:a=>O.cron.trigger(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]})}}),A=K({mutationFn:a=>O.cron.pause(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),H=K({mutationFn:a=>O.cron.resume(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),T=K({mutationFn:a=>O.cron.delete(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]}),u(null)}}),n=K({mutationFn:a=>O.cron.archive(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),R=K({mutationFn:a=>O.cron.restore(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),fe=r.useCallback(a=>{q.mutate(a)},[q]),U=r.useCallback(a=>{A.mutate(a)},[A]),be=r.useCallback(a=>{H.mutate(a)},[H]),ve=r.useCallback(a=>{b(a.id),m(a.name)},[]),je=r.useCallback(a=>{u(a)},[]),Q=r.useCallback(a=>{w(a)},[]),X=r.useCallback(a=>{n.mutate(a)},[n]),I=r.useCallback(a=>{R.mutate(a)},[R]),Z=()=>{x&&T.mutate(x)};return F?e.jsxs("div",{className:"glass rounded-[28px] p-12 text-center",children:[e.jsx(he,{className:"h-12 w-12 mx-auto text-red-400 mb-4"}),e.jsx("p",{className:"text-lg font-bold text-red-400",children:"Error loading scheduled jobs"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:F.message}),e.jsxs(D,{variant:"outline",onClick:()=>p(),className:"mt-4",children:[e.jsx(re,{className:"h-4 w-4 mr-2"}),"Retry"]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("header",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-bold tracking-tight flex items-center gap-2",children:[e.jsx(J,{className:"h-6 w-6 text-primary"}),"Scheduled Jobs"]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage automated tasks with cron schedules or fixed intervals"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>p(),disabled:k,children:[e.jsx(re,{className:l("h-4 w-4 mr-2",k&&"animate-spin")}),"Refresh"]}),e.jsx(ms,{})]})]}),E&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4",children:[e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Total Jobs"})]}),e.jsx("div",{className:"text-2xl font-bold",children:E.total})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-500 mb-1",children:[e.jsx(ps,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Active"})]}),e.jsx("div",{className:"text-2xl font-bold text-green-500",children:E.active})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-500 mb-1",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Paused"})]}),e.jsx("div",{className:"text-2xl font-bold text-amber-500",children:E.paused})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(xe,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Total Runs"})]}),e.jsx("div",{className:"text-2xl font-bold",children:E.totalRuns})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-500 mb-1",children:[e.jsx(tt,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Successes"})]}),e.jsx("div",{className:"text-2xl font-bold text-green-500",children:E.totalSuccesses})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-500 mb-1",children:[e.jsx(ae,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Failures"})]}),e.jsx("div",{className:"text-2xl font-bold text-red-500",children:E.totalFailures})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[e.jsx(Os,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(C,{placeholder:"Search jobs...",value:o,onChange:a=>f(a.target.value),className:"pl-10 bg-white/5 border-white/10 rounded-xl"})]}),e.jsxs(Fe,{children:[e.jsx(Ie,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(at,{className:"h-4 w-4"}),xs.find(a=>a.value===i)?.label]})}),e.jsx(Oe,{align:"start",children:xs.map(a=>{const ee=a.icon;return e.jsxs(z,{onClick:()=>j(a.value),className:l(i===a.value&&"bg-primary/10"),children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),a.label]},a.value)})})]}),e.jsxs(Fe,{children:[e.jsx(Ie,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(gs,{className:"h-4 w-4"}),us.find(a=>a.value===h)?.label]})}),e.jsx(Oe,{align:"start",children:us.map(a=>{const ee=a.icon;return e.jsxs(z,{onClick:()=>N(a.value),className:l(h===a.value&&"bg-primary/10"),children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),a.label]},a.value)})})]})]}),k?e.jsxs("div",{className:"glass rounded-[28px] p-12 flex flex-col items-center justify-center",children:[e.jsx(ne,{className:"h-8 w-8 animate-spin text-primary mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading scheduled jobs..."})]}):M.length===0?e.jsxs("div",{className:"glass rounded-[28px] p-12 text-center",children:[e.jsx(J,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-1",children:o||i!=="all"||h!=="all"?"No jobs match your filters":"No scheduled jobs yet"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:o||i!=="all"||h!=="all"?"Try adjusting your search or filters":"Create your first scheduled job to automate tasks"}),!(o||i!=="all"||h!=="all")&&e.jsx(ms,{})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:M.map(a=>e.jsx(vt,{job:a,onTrigger:fe,onPause:U,onResume:be,onDelete:je,onViewHistory:()=>ve(a),onEdit:Q,onArchive:X,onRestore:I},a.id))}),e.jsx(kt,{jobId:c,jobName:d,open:!!c,onOpenChange:a=>!a&&b(null)}),e.jsx(Pt,{job:P,open:!!P,onOpenChange:a=>!a&&w(null)}),e.jsx(Js,{open:!!x,onOpenChange:a=>!a&&u(null),children:e.jsxs(Ls,{children:[e.jsxs(zs,{children:[e.jsx(qs,{children:"Delete Scheduled Job?"}),e.jsx(_s,{children:"This will permanently delete this job and all its run history. This action cannot be undone."})]}),e.jsxs($s,{children:[e.jsx(Hs,{children:"Cancel"}),e.jsx(Us,{onClick:Z,className:"bg-red-500 hover:bg-red-600",disabled:T.isPending,children:T.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):"Delete Job"})]})]})})]})}export{ms as CreateJobModal,na as CronDashboard,Pt as EditJobModal,vt as JobCard,kt as JobHistoryModal};
|
|
1
|
+
import{c as le,r,K as ue,C as G,g as J,j as e,i as l,D as Fe,x as Ie,k as D,y as Oe,z,Z as xe,aw as is,R as re,u as Ne,L as ne,U as he,m as O,n as ze,S as qe,a1 as hs,M as ps,ay as gs,o as K,P as fs,O as Ms,l as Rs,p as g,aK as Je,aj as Ds,I as C,v as we,_ as As,be as Ps,A as Fs,X as Is,w as Os}from"./index-lJlNPFVJ.js";import{A as Js,a as Ls,b as zs,c as qs,d as _s,e as $s,f as Hs,g as Us}from"./alert-dialog-SKM6Gjz4.js";import{M as Ce}from"./message-square-CBgH65X7.js";import{W as Y}from"./wrench-02YaOSiK.js";import{G as Se}from"./globe-f-jjCa_g.js";import{A as _e}from"./archive-BsLa7brF.js";import{C as ae}from"./circle-x-Dgw11LgT.js";import{E as Ks}from"./ellipsis-vertical-DoULYEKn.js";import{P as Gs}from"./pencil-CYXCEPQh.js";import{H as Qs}from"./history-BQSBo_1Q.js";import{P as ke}from"./play-d1ONaH0-.js";import{T as bs}from"./trash-2-keO5tKPE.js";import{T as vs}from"./tag-C35mgoEv.js";import{T as pe,C as De,I as Le,S as Ws}from"./timer-DHJBS2w1.js";import{D as $e,b as He,c as Ue,d as Ke,a as Bs}from"./dialog-BUqN9Psj.js";import{S as js}from"./settings-2-ocj5uHGx.js";import{L as Vs}from"./link-2-DdO7ostF.js";import{W as Ys}from"./wand-sparkles-BusQ52ZK.js";import{G as Xs}from"./git-branch-C_K30am0.js";import{D as Zs}from"./database-BwTfupDi.js";import{F as et}from"./file-code-B2UrJLwi.js";import{C as Te}from"./calendar-Bf0t2B82.js";import{L as st}from"./lightbulb-Jhp7FvbU.js";import{T as tt}from"./trending-up-BBv8KbrY.js";import{F as at}from"./funnel-PkaD_HSR.js";const rt=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]],nt=le("archive-restore",rt);const lt=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],it=le("hard-drive",lt);const ot=[["path",{d:"M11 6a13 13 0 0 0 8.4-2.8A1 1 0 0 1 21 4v12a1 1 0 0 1-1.6.8A13 13 0 0 0 11 14H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z",key:"q8bfy3"}],["path",{d:"M6 14a12 12 0 0 0 2.4 7.2 2 2 0 0 0 3.2-2.4A8 8 0 0 1 10 14",key:"1853fq"}],["path",{d:"M8 6v8",key:"15ugcq"}]],ct=le("megaphone",ot);const dt=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],ge=le("pause",dt);const mt=[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]],os=le("refresh-ccw",mt);const xt=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],ut=le("sliders-horizontal",xt),ht={http:Se,tool:Y,script:ue,message:Ce},pt={active:{color:"text-green-500",bg:"bg-green-500/10",icon:G,label:"Active"},paused:{color:"text-amber-500",bg:"bg-amber-500/10",icon:ge,label:"Paused"},completed:{color:"text-blue-500",bg:"bg-blue-500/10",icon:G,label:"Completed"},failed:{color:"text-red-500",bg:"bg-red-500/10",icon:ae,label:"Failed"},archived:{color:"text-muted-foreground",bg:"bg-muted/50",icon:_e,label:"Archived"}},gt={color:"text-muted-foreground",bg:"bg-muted/50",icon:J,label:"Unknown"};function ft(t){if(!t)return"Not scheduled";const o=new Date(t),f=new Date,i=o.getTime()-f.getTime();return i<0?"Overdue":i<6e4?"In less than a minute":i<36e5?`In ${Math.round(i/6e4)} min`:i<864e5?`In ${Math.round(i/36e5)} hours`:o.toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function bt(t){if(!t)return"Never";const o=new Date(t),i=new Date().getTime()-o.getTime();return i<6e4?"Just now":i<36e5?`${Math.round(i/6e4)} min ago`:i<864e5?`${Math.round(i/36e5)} hours ago`:o.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function vt({job:t,onTrigger:o,onPause:f,onResume:i,onDelete:j,onViewHistory:h,onEdit:N,onArchive:c,onRestore:b}){const[d,m]=r.useState(!1),x=ht[t.jobType]||Y,u=pt[t.status]||gt,P=u.icon,w=t.status==="archived",L=async()=>{m(!0);try{await o(t.id)}finally{m(!1)}},k=t.runCount>0?Math.round(t.successCount/t.runCount*100):0;return e.jsxs("div",{className:"group relative rounded-2xl border border-border/50 bg-card/50 backdrop-blur-sm p-4 hover:border-border hover:shadow-lg transition-all duration-200",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:l("h-10 w-10 rounded-xl flex items-center justify-center shrink-0",u.bg),children:e.jsx(x,{className:l("h-5 w-5",u.color)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm truncate",children:t.name}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:t.description})]})]}),e.jsxs(Fe,{children:[e.jsx(Ie,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 opacity-0 group-hover:opacity-100",children:e.jsx(Ks,{className:"h-4 w-4"})})}),e.jsxs(Oe,{align:"end",className:"w-48",children:[!w&&e.jsxs(e.Fragment,{children:[e.jsxs(z,{onClick:L,disabled:d,children:[e.jsx(xe,{className:"h-4 w-4 mr-2"}),"Run Now"]}),N&&e.jsxs(z,{onClick:()=>N(t),children:[e.jsx(Gs,{className:"h-4 w-4 mr-2"}),"Edit Job"]})]}),e.jsxs(z,{onClick:()=>h(t.id),children:[e.jsx(Qs,{className:"h-4 w-4 mr-2"}),"View History"]}),e.jsx(is,{}),!w&&t.status==="active"&&e.jsxs(z,{onClick:()=>f(t.id),children:[e.jsx(ge,{className:"h-4 w-4 mr-2"}),"Pause Job"]}),!w&&t.status==="paused"&&e.jsxs(z,{onClick:()=>i(t.id),children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Resume Job"]}),w&&b&&e.jsxs(z,{onClick:()=>b(t.id),children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),"Restore Job"]}),e.jsx(is,{}),!w&&c&&e.jsxs(z,{onClick:()=>c(t.id),className:"text-amber-500 focus:text-amber-500",children:[e.jsx(_e,{className:"h-4 w-4 mr-2"}),"Archive Job"]}),e.jsxs(z,{onClick:()=>j(t.id),className:"text-red-500 focus:text-red-500",children:[e.jsx(bs,{className:"h-4 w-4 mr-2"}),"Delete Permanently"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("span",{className:l("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold",u.bg,u.color),children:[e.jsx(P,{className:"h-3 w-3"}),u.label]}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:t.cronExpression||`Every ${Math.round((t.intervalMs||0)/1e3)}s`})]}),t.labels&&t.labels.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mb-3",children:[t.labels.slice(0,3).map(F=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[9px]",children:[e.jsx(vs,{className:"h-2.5 w-2.5"}),F]},F)),t.labels.length>3&&e.jsxs("span",{className:"text-[9px] text-muted-foreground",children:["+",t.labels.length-3]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-3",children:[e.jsxs("div",{className:"text-center p-2 rounded-lg bg-muted/50",children:[e.jsx("div",{className:"text-lg font-bold",children:t.runCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Total Runs"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:l("text-lg font-bold",k>=80?"text-green-500":k>=50?"text-amber-500":"text-red-500"),children:[k,"%"]}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Success"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-muted/50",children:[e.jsx("div",{className:"text-lg font-bold text-red-500",children:t.failureCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Failures"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t border-border/50 pt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:["Last: ",bt(t.lastRunAt)]}),t.lastRunStatus&&e.jsx("span",{className:l("h-1.5 w-1.5 rounded-full",t.lastRunStatus==="success"?"bg-green-500":"bg-red-500")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:ft(t.nextRunAt)})]})]}),e.jsx(D,{variant:"outline",size:"sm",className:"w-full mt-3 h-8 text-xs",onClick:L,disabled:d||t.status==="completed",children:d?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),"Running..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-3.5 w-3.5 mr-1.5"}),"Run Now"]})})]})}const jt={pending:{color:"text-amber-500",bg:"bg-amber-500/10",icon:J,label:"Pending"},running:{color:"text-blue-500",bg:"bg-blue-500/10",icon:ne,label:"Running"},success:{color:"text-green-500",bg:"bg-green-500/10",icon:G,label:"Success"},failure:{color:"text-red-500",bg:"bg-red-500/10",icon:ae,label:"Failed"},error:{color:"text-red-500",bg:"bg-red-500/10",icon:ae,label:"Error"},timeout:{color:"text-orange-500",bg:"bg-orange-500/10",icon:he,label:"Timeout"},cancelled:{color:"text-muted-foreground",bg:"bg-muted/50",icon:ae,label:"Cancelled"}},yt={color:"text-muted-foreground",bg:"bg-muted/50",icon:he,label:"Unknown"};function Nt(t){return t?t<1e3?`${t}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${Math.round(t/6e4)}m ${Math.round(t%6e4/1e3)}s`:"-"}function wt(t){return new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}function kt({jobId:t,jobName:o,open:f,onOpenChange:i}){const{data:j,isLoading:h,error:N,refetch:c}=Ne({queryKey:["cron-history",t],queryFn:()=>O.cron.history(t,50),enabled:!!t&&f,refetchInterval:5e3}),b=j?.history||[],d=j?.job;return e.jsx($e,{open:f,onOpenChange:i,children:e.jsxs(He,{className:"max-w-2xl max-h-[80vh] flex flex-col",children:[e.jsx(Ue,{className:"flex-shrink-0",children:e.jsxs(Ke,{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5 text-primary"}),"Job History: ",o||t?.slice(0,8)]})}),d&&e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-xl bg-muted/50 border border-border/50 mb-4",children:[e.jsxs("div",{className:"flex-1 text-center",children:[e.jsx("div",{className:"text-2xl font-bold",children:d.runCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Total Runs"})]}),e.jsx("div",{className:"h-8 w-px bg-border"}),e.jsxs("div",{className:"flex-1 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-500",children:d.successCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Successes"})]}),e.jsx("div",{className:"h-8 w-px bg-border"}),e.jsxs("div",{className:"flex-1 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-red-500",children:d.failureCount}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Failures"})]}),e.jsx("div",{className:"h-8 w-px bg-border"}),e.jsxs("div",{className:"flex-1 text-center",children:[e.jsxs("div",{className:"text-2xl font-bold",children:[d.runCount>0?Math.round(d.successCount/d.runCount*100):0,"%"]}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Success Rate"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto -mx-6 px-6",children:h?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(ne,{className:"h-8 w-8 animate-spin text-primary mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading history..."})]}):N?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(he,{className:"h-8 w-8 text-red-500 mb-3"}),e.jsx("p",{className:"text-sm text-red-500",children:"Failed to load history"}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>c(),className:"mt-3",children:[e.jsx(re,{className:"h-4 w-4 mr-2"}),"Retry"]})]}):b.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(J,{className:"h-8 w-8 text-muted-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No runs yet"}),e.jsx("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"History will appear here after the first execution"})]}):e.jsx("div",{className:"space-y-2",children:b.map((m,x)=>{const u=jt[m.status]||yt,P=u.icon,w=m.status==="running";return e.jsxs("div",{className:l("rounded-xl border p-3 transition-colors",x===0?"border-primary/30 bg-primary/5":"border-border/50 bg-card/50"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:l("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold",u.bg,u.color),children:[e.jsx(P,{className:l("h-3 w-3",w&&"animate-spin")}),u.label]}),x===0&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-primary/10 text-primary",children:"Latest"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),Nt(m.durationMs)]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),wt(m.startedAt)]})]})]}),(m.output||m.error)&&e.jsx("div",{className:l("mt-2 p-2 rounded-lg text-xs font-mono overflow-x-auto",m.error?"bg-red-500/10 text-red-400":"bg-muted/50 text-muted-foreground"),children:e.jsx("pre",{className:"whitespace-pre-wrap break-words max-h-32 overflow-y-auto",children:m.error||m.output})})]},m.id)})})}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-border/50 mt-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing ",b.length," runs"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>c(),children:[e.jsx(re,{className:"h-3.5 w-3.5 mr-1.5"}),"Refresh"]})]})]})})}const V=[{id:"type",label:"Type",icon:qe,description:"What kind of job?"},{id:"schedule",label:"Schedule",icon:J,description:"When to run?"},{id:"config",label:"Configure",icon:js,description:"Job details"},{id:"review",label:"Review",icon:hs,description:"Confirm & create"}],cs=[{id:"health-check",name:"Health Check",category:"monitoring",icon:ps,description:"Monitor service health with HTTP pings",jobType:"http",suggestedCron:"*/5 * * * *",payload:{url:"https://your-api.com/health",method:"GET"},guide:"Regularly checks if your service is responding. Great for uptime monitoring."},{id:"db-backup",name:"Database Backup",category:"maintenance",icon:it,description:"Schedule automated database backups",jobType:"script",suggestedCron:"0 2 * * *",payload:{command:"pg_dump",args:["-h","localhost","mydb"]},guide:"Runs daily at 2 AM. Adjust the command for your database type.",warning:"Ensure backup storage has sufficient space."},{id:"git-sync",name:"Git Repository Sync",category:"development",icon:re,description:"Pull latest changes from remote",jobType:"tool",suggestedCron:"*/30 * * * *",payload:{tool:"git_pull",params:{branch:"main"}},guide:"Keeps local repositories in sync with remote."},{id:"slack-standup",name:"Daily Standup Reminder",category:"notifications",icon:ct,description:"Send daily standup reminders to Slack",jobType:"message",suggestedCron:"0 9 * * 1-5",payload:{channel:"#team",message:"Good morning! Time for standup!"},guide:"Sends at 9 AM on weekdays. Change channel and message as needed."},{id:"api-sync",name:"External API Sync",category:"integration",icon:Vs,description:"Sync data from external APIs",jobType:"http",suggestedCron:"0 */4 * * *",payload:{url:"https://api.example.com/sync",method:"POST",headers:{"Content-Type":"application/json"}},guide:"Runs every 4 hours. Add authentication headers if required."},{id:"cleanup",name:"Cleanup Old Files",category:"maintenance",icon:bs,description:"Remove temporary and old files",jobType:"script",suggestedCron:"0 3 * * 0",payload:{command:"find",args:["/tmp","-mtime","+7","-delete"]},guide:"Runs weekly on Sunday at 3 AM.",warning:"Double-check paths before enabling to avoid data loss."},{id:"report-gen",name:"Generate Reports",category:"analytics",icon:gs,description:"Generate and send automated reports",jobType:"tool",suggestedCron:"0 8 * * 1",payload:{tool:"generate_report",params:{type:"weekly",format:"pdf"}},guide:"Generates weekly reports every Monday at 8 AM."},{id:"webhook-trigger",name:"Webhook Trigger",category:"integration",icon:xe,description:"Trigger external webhooks on schedule",jobType:"http",suggestedCron:"0 */6 * * *",payload:{url:"https://hooks.example.com/trigger",method:"POST",body:{event:"scheduled"}},guide:"Triggers every 6 hours. Customize the webhook URL and payload."}],Ct=[{id:"all",label:"All",icon:qe},{id:"monitoring",label:"Monitoring",icon:hs},{id:"maintenance",label:"Maintenance",icon:Y},{id:"development",label:"Development",icon:Xs},{id:"notifications",label:"Notifications",icon:Je},{id:"integration",label:"Integration",icon:Ds},{id:"analytics",label:"Analytics",icon:Zs}],te=[{type:"http",label:"HTTP Request",icon:Se,description:"Call an API endpoint",color:"from-blue-500/20 to-cyan-500/20",examples:["Sync data from API","Health checks","Webhook triggers"],defaultPayload:{url:"https://api.example.com/endpoint",method:"POST",headers:{}},guide:"Make HTTP requests to external services. Supports GET, POST, PUT, DELETE methods."},{type:"tool",label:"Tool Execution",icon:Y,description:"Run a profClaw tool",color:"from-indigo-500/20 to-pink-500/20",examples:["Git operations","File sync","Database backups"],defaultPayload:{tool:"git_status",params:{}},guide:"Execute any registered profClaw tool with custom parameters."},{type:"script",label:"Shell Script",icon:ue,description:"Execute a command",color:"from-green-500/20 to-emerald-500/20",examples:["Build scripts","Cleanup tasks","System checks"],defaultPayload:{command:'echo "Hello World"',args:[]},guide:"Run shell commands on the server. Use with caution.",warning:"Scripts run with server permissions. Avoid sensitive operations."},{type:"message",label:"Notification",icon:Ce,description:"Send a message",color:"from-orange-500/20 to-amber-500/20",examples:["Daily standup reminder","Status reports","Alerts"],defaultPayload:{channel:"#general",message:"Scheduled notification"},guide:"Send messages to Slack channels, email, or webhooks."}],St=[{type:"cron",label:"Cron",icon:J,description:"Classic cron syntax"},{type:"interval",label:"Interval",icon:pe,description:"Every X seconds"},{type:"oneshot",label:"One-Time",icon:Te,description:"Run once"},{type:"event",label:"Event",icon:xe,description:"On trigger"}],ys=[{label:"Every minute",value:"* * * * *",humanize:"Runs every minute"},{label:"Every 5 min",value:"*/5 * * * *",humanize:"Runs every 5 minutes"},{label:"Every 15 min",value:"*/15 * * * *",humanize:"Runs every 15 minutes"},{label:"Hourly",value:"0 * * * *",humanize:"Runs at the start of every hour"},{label:"Daily midnight",value:"0 0 * * *",humanize:"Runs daily at midnight"},{label:"Weekdays 9am",value:"0 9 * * 1-5",humanize:"Runs at 9am on weekdays"}],Ae=[{label:"30 sec",value:30,humanize:"Every 30 seconds"},{label:"1 min",value:60,humanize:"Every minute"},{label:"5 min",value:300,humanize:"Every 5 minutes"},{label:"15 min",value:900,humanize:"Every 15 minutes"},{label:"30 min",value:1800,humanize:"Every 30 minutes"},{label:"1 hour",value:3600,humanize:"Every hour"}],Tt=[{type:"webhook",label:"Webhook",description:"HTTP webhook endpoint"},{type:"ticket",label:"Ticket",description:"Ticket changes"},{type:"github",label:"GitHub",description:"Push, PR, issues"},{type:"file",label:"File",description:"File changes"}];function _({children:t,type:o="info"}){const f={info:"bg-blue-500/10 border-blue-500/20 text-blue-700 dark:text-blue-300",warning:"bg-amber-500/10 border-amber-500/20 text-amber-700 dark:text-amber-300",tip:"bg-green-500/10 border-green-500/20 text-green-700 dark:text-green-300"},j={info:Le,warning:he,tip:st}[o];return e.jsxs("div",{className:l("flex items-start gap-2 p-3 rounded-lg border text-xs",f[o]),children:[e.jsx(j,{className:"h-4 w-4 shrink-0 mt-0.5"}),e.jsx("div",{children:t})]})}function Pe({children:t,content:o}){return e.jsxs("span",{className:"relative group",children:[t,e.jsx("span",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 rounded bg-popover border text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-50",children:o})]})}function ds(t){const o=ys.find(b=>b.value===t);if(o)return o.humanize;const f=t.split(" ");if(f.length!==5)return`Cron: ${t}`;const[i,j,h,N,c]=f;return i.startsWith("*/")&&j==="*"&&h==="*"&&N==="*"&&c==="*"?`Every ${i.slice(2)} minutes`:i==="0"&&j.startsWith("*/")&&h==="*"&&N==="*"&&c==="*"?`Every ${j.slice(2)} hours`:i==="0"&&j==="0"&&h==="*"&&N==="*"&&c==="*"?"Daily at midnight":`Cron: ${t}`}function Et(t){try{return{valid:!0,parsed:JSON.parse(t)}}catch{return{valid:!1,error:"Invalid JSON syntax"}}}function ms({open:t,onOpenChange:o}){const f=ze(),[i,j]=r.useState(!1),h=t??i,N=o??j,[c,b]=r.useState("simple"),[d,m]=r.useState("type"),x=V.findIndex(s=>s.id===d),[u,P]=r.useState("all"),[w,L]=r.useState(""),[k,F]=r.useState(""),[p,$]=r.useState(null),[v,E]=r.useState(null),[M,q]=r.useState("*/5 * * * *"),[A,H]=r.useState(300),[T,n]=r.useState(""),[R,fe]=r.useState(""),[U,be]=r.useState("webhook"),[ve,je]=r.useState("{}"),[Q,X]=r.useState("{}"),[I,Z]=r.useState(null),[a,ee]=r.useState("UTC"),[ie,Ge]=r.useState(!0),[Ee,Qe]=r.useState(3),[Me,We]=r.useState("exponential"),[oe,Be]=r.useState(!1),[W,Ve]=r.useState(""),[Ye,Xe]=r.useState(!1),[Ze,es]=r.useState(!0),[ss,ts]=r.useState(!1),[ce,as]=r.useState(null),[Re,rs]=r.useState(null),de=r.useMemo(()=>Et(Q),[Q]),{data:Ns}=Ne({queryKey:["cron-templates"],queryFn:()=>O.cron.listTemplates?.()||Promise.resolve({templates:[]}),enabled:h}),ns=Ns?.templates||[],ws=r.useMemo(()=>u==="all"?cs:cs.filter(s=>s.category===u),[u]);r.useEffect(()=>{if(p&&!I){const s=te.find(y=>y.type===p);s&&X(JSON.stringify(s.defaultPayload,null,2))}},[p,I]);const ls=s=>{if(I?.id===s.id){Z(null);return}Z(s),L(s.name),F(s.description??""),$(s.jobType),X(JSON.stringify(s.payload,null,2)),s.suggestedCron&&(E("cron"),q(s.suggestedCron))},se=K({mutationFn:()=>{const s=JSON.parse(Q);let y;v==="oneshot"&&T&&R&&(y=new Date(`${T}T${R}`).toISOString());let S;if(v==="event")try{S={type:U,config:JSON.parse(ve)}}catch{S={type:U,config:{}}}let B;return c==="advanced"&&oe&&W&&(B={channels:[{type:W.includes("@")?"email":W.startsWith("http")?"webhook":"slack",target:W,onSuccess:Ye,onFailure:Ze}]}),O.cron.create({name:w,description:k||void 0,jobType:p,cronExpression:v==="cron"?M:void 0,intervalMs:v==="interval"?A*1e3:void 0,runAt:y,eventTrigger:S,payload:s,timezone:c==="advanced"?a:"UTC",deleteOnComplete:v==="oneshot"?ss:void 0,retryPolicy:c==="advanced"?{enabled:ie,maxRetries:Ee,backoff:Me}:void 0,delivery:B,maxRuns:c==="advanced"&&ce||void 0,maxFailures:c==="advanced"&&Re||void 0})},onSuccess:()=>{f.invalidateQueries({queryKey:["cron-jobs"]}),f.invalidateQueries({queryKey:["cron-stats"]}),N(!1),ks()}}),ks=()=>{m("type"),b("simple"),P("all"),L(""),F(""),$(null),E(null),q("*/5 * * * *"),H(300),n(""),fe(""),be("webhook"),je("{}"),X("{}"),Z(null),ee("UTC"),Ge(!0),Qe(3),We("exponential"),Be(!1),Ve(""),Xe(!1),es(!0),ts(!1),as(null),rs(null)},Cs=r.useMemo(()=>{switch(d){case"type":return p!==null;case"schedule":return v?v==="oneshot"?T&&R:!0:!1;case"config":return w.trim().length>0&&de.valid;case"review":return!0;default:return!1}},[d,p,v,T,R,w,de]),Ss=()=>{x<V.length-1&&m(V[x+1].id)},Ts=()=>{x>0&&m(V[x-1].id)},Es=r.useMemo(()=>{switch(v){case"cron":return ds(M);case"interval":return Ae.find(s=>s.value===A)?.humanize||`Every ${A} seconds`;case"oneshot":return T&&R?`Once at ${new Date(`${T}T${R}`).toLocaleString()}`:"One-time (not scheduled)";case"event":return`On ${U} event`;default:return"Not configured"}},[v,M,A,T,R,U]),ye=te.find(s=>s.type===p);return e.jsxs($e,{open:h,onOpenChange:N,children:[e.jsx(Bs,{asChild:!0,children:e.jsxs(D,{className:"gap-2 shadow-lg shadow-primary/20 hover:shadow-primary/30 transition-shadow",children:[e.jsx(fs,{className:"h-4 w-4"}),"Create Job"]})}),e.jsxs(He,{className:"max-w-4xl w-[90vw] max-h-[85vh] my-8 flex flex-col p-0 overflow-hidden [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",children:[e.jsxs("div",{className:"border-b border-border/20 bg-linear-to-r from-primary/5 to-transparent",children:[e.jsx(Ue,{className:"px-6 pt-5 pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Ke,{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(J,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"block",children:"Create Scheduled Job"}),e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:V[x].description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 p-1 rounded-lg bg-muted",children:[e.jsxs("button",{onClick:()=>b("simple"),className:l("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-all",c==="simple"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(Ys,{className:"h-3 w-3"}),"Simple"]}),e.jsxs("button",{onClick:()=>b("advanced"),className:l("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-all",c==="advanced"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(ut,{className:"h-3 w-3"}),"Advanced"]})]})]})}),e.jsx("div",{className:"px-6 pb-4",children:e.jsx("div",{className:"flex items-center gap-2",children:V.map((s,y)=>{const S=s.icon,B=s.id===d,me=y<x;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>y<=x&&m(s.id),disabled:y>x,className:l("flex items-center gap-2 px-3 py-1.5 rounded-full text-xs font-medium transition-all",B&&"bg-primary text-primary-foreground shadow-md shadow-primary/30",me&&"bg-primary/20 text-primary hover:bg-primary/30",!B&&!me&&"bg-muted text-muted-foreground",y>x&&"opacity-50 cursor-not-allowed"),children:[me?e.jsx(Ms,{className:"h-3 w-3"}):e.jsx(S,{className:"h-3 w-3"}),e.jsx("span",{className:"hidden sm:inline",children:s.label})]}),y<V.length-1&&e.jsx(Rs,{className:l("h-4 w-4",y<x?"text-primary":"text-muted-foreground/50")})]},s.id)})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",children:[d==="type"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[c==="simple"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Quick Start Templates"}),e.jsx(Pe,{content:"Pre-configured jobs for common tasks",children:e.jsx(De,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"})})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:Ct.map(s=>{const y=s.icon,S=u===s.id;return e.jsxs("button",{onClick:()=>P(s.id),className:l("flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-medium transition-all",S?"bg-foreground text-background shadow-sm":"bg-muted text-muted-foreground hover:bg-muted/80"),children:[e.jsx(y,{className:"h-3 w-3"}),s.label]},s.id)})}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ws.map(s=>{const y=s.icon;return e.jsxs("button",{onClick:()=>ls(s),className:l("flex items-start gap-3 p-3 rounded-xl text-left transition-all hover:scale-[1.01]",I?.id===s.id?"bg-primary/5 ring-2 ring-primary/20":"bg-muted/30 hover:bg-muted/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-lg shrink-0",I?.id===s.id?"bg-primary/20 text-primary":"bg-muted text-muted-foreground"),children:e.jsx(y,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsx("div",{className:"text-[10px] text-muted-foreground line-clamp-2",children:s.description})]})]},s.id)})}),ns.length>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t",children:[e.jsx(g,{className:"text-xs text-muted-foreground",children:"Your Templates"}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:ns.slice(0,4).map(s=>e.jsxs("button",{onClick:()=>ls({id:s.id,name:s.name,category:s.category,description:s.description,jobType:s.jobType,payload:s.payloadTemplate,suggestedCron:s.suggestedCron}),className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-muted/30 hover:bg-muted/50 text-xs",children:[e.jsx(et,{className:"h-3 w-3 text-primary"}),s.name]},s.id))})]}),e.jsx("div",{className:"mt-4",children:e.jsx(_,{type:"tip",children:"Select a template to get started quickly, or choose a job type below for custom configuration."})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:c==="simple"?"Or Choose Job Type":"Job Type"})}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:te.map(s=>{const y=s.icon,S=p===s.type;return e.jsxs("button",{onClick:()=>{$(s.type),Z(null)},className:l("relative overflow-hidden group p-4 rounded-2xl text-left transition-all duration-200",S?"bg-primary/5 ring-2 ring-primary/20 scale-[1.02]":"bg-muted/30 hover:bg-muted/50 hover:scale-[1.01]"),children:[e.jsx("div",{className:l("absolute inset-0 bg-linear-to-br opacity-0 transition-opacity",s.color,S&&"opacity-100","group-hover:opacity-50")}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:l("p-2 rounded-lg transition-colors",S?"bg-primary text-primary-foreground":"bg-muted"),children:e.jsx(y,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:l("font-semibold",S&&"text-primary"),children:s.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.description})]}),S&&e.jsx(G,{className:"h-5 w-5 text-primary"})]}),c==="advanced"&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-3",children:s.examples.map((B,me)=>e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-muted/80 text-[10px] text-muted-foreground",children:B},me))})]})]},s.type)})}),ye&&e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx(_,{type:"info",children:ye.guide}),ye.warning&&e.jsx(_,{type:"warning",children:ye.warning})]})]})]}),d==="schedule"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"When to Run?"}),e.jsx("div",{className:"grid grid-cols-4 gap-2 mt-3",children:St.map(s=>{const y=s.icon,S=v===s.type;return e.jsxs("button",{onClick:()=>E(s.type),className:l("flex flex-col items-center gap-2 p-4 rounded-xl transition-all",S?"bg-primary/5 ring-2 ring-primary/20":"bg-muted/30 hover:bg-muted/50"),children:[e.jsx(y,{className:l("h-6 w-6",S?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:l("text-xs font-medium",S&&"text-primary"),children:s.label})]},s.type)})})]}),v==="cron"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"cron",children:"Cron Expression"}),e.jsx(C,{id:"cron",placeholder:"*/5 * * * *",value:M,onChange:s=>q(s.target.value),className:"mt-2 font-mono text-sm"}),e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(ke,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:ds(M)})]})})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs text-muted-foreground",children:"Presets"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:ys.map(s=>e.jsx("button",{onClick:()=>q(s.value),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",M===s.value?"bg-primary text-primary-foreground shadow-md":"bg-muted hover:bg-muted/80"),children:s.label},s.value))})]}),e.jsxs(_,{type:"info",children:["Cron format: ",e.jsx("code",{className:"font-mono bg-muted px-1 rounded",children:"minute hour day month weekday"}),e.jsx("br",{}),"Use ",e.jsx("code",{className:"font-mono bg-muted px-1 rounded",children:"*"})," for any value, ",e.jsx("code",{className:"font-mono bg-muted px-1 rounded",children:"*/N"})," for every N units."]})]}),v==="interval"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"interval",children:"Interval (seconds)"}),e.jsx(C,{id:"interval",type:"number",min:1,value:A,onChange:s=>H(parseInt(s.target.value)||60),className:"mt-2"}),e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(pe,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:Ae.find(s=>s.value===A)?.humanize||`Every ${A} seconds`})]})})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ae.map(s=>e.jsx("button",{onClick:()=>H(s.value),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",A===s.value?"bg-primary text-primary-foreground shadow-md":"bg-muted hover:bg-muted/80"),children:s.label},s.value))})]}),v==="oneshot"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Run At"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mt-2",children:[e.jsxs("div",{children:[e.jsx(C,{type:"date",value:T,onChange:s=>n(s.target.value),min:new Date().toISOString().split("T")[0]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Date"})]}),e.jsxs("div",{children:[e.jsx(C,{type:"time",value:R,onChange:s=>fe(s.target.value)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Time"})]})]}),T&&R&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:new Date(`${T}T${R}`).toLocaleString()})]})})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ss,onChange:s=>ts(s.target.checked),className:"rounded"}),e.jsx("span",{className:"text-muted-foreground",children:"Auto-delete after completion"})]}),e.jsx(_,{type:"info",children:"One-shot jobs run exactly once at the specified time and can optionally be deleted afterward."})]}),v==="event"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-200",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Event Type"}),e.jsx("div",{className:"grid grid-cols-4 gap-2 mt-2",children:Tt.map(s=>e.jsxs("button",{onClick:()=>be(s.type),className:l("flex flex-col items-center p-3 rounded-xl text-center transition-all",U===s.type?"bg-primary/5 ring-2 ring-primary/20":"bg-muted/30 hover:bg-muted/50"),children:[e.jsx("span",{className:l("text-xs font-medium",U===s.type&&"text-primary"),children:s.label}),e.jsx("span",{className:"text-[9px] text-muted-foreground mt-0.5",children:s.description})]},s.type))})]}),c==="advanced"&&e.jsxs("div",{children:[e.jsx(g,{htmlFor:"eventConfig",children:"Event Config (JSON)"}),e.jsx(C,{id:"eventConfig",placeholder:'{"source": "webhook"}',value:ve,onChange:s=>je(s.target.value),className:"mt-2 font-mono text-xs"})]}),e.jsx(_,{type:"info",children:"Event-triggered jobs run when specific events occur, like webhooks or file changes."})]}),c==="advanced"&&v==="cron"&&e.jsxs("div",{children:[e.jsx(g,{htmlFor:"timezone",children:"Timezone"}),e.jsx(C,{id:"timezone",placeholder:"UTC",value:a,onChange:s=>ee(s.target.value),className:"mt-2"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Default: UTC. Use IANA timezone names (e.g., America/New_York)."})]})]}),d==="config"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[I?.guide&&e.jsxs(_,{type:"tip",children:[e.jsxs("strong",{children:[I.name,":"]})," ",I.guide]}),I?.warning&&e.jsx(_,{type:"warning",children:I.warning}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"name",className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Job Name *"}),e.jsx(C,{id:"name",placeholder:"e.g., Sync GitHub Issues",value:w,onChange:s=>L(s.target.value),className:"mt-2 text-lg font-medium"})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"description",className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Description"}),e.jsx(C,{id:"description",placeholder:"What this job does...",value:k,onChange:s=>F(s.target.value),className:"mt-2"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(g,{htmlFor:"payload",className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Payload (JSON)"}),de.valid?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-600",children:[e.jsx(G,{className:"h-3 w-3"})," Valid"]}):e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[e.jsx(we,{className:"h-3 w-3"})," ",de.error]})]}),e.jsx("textarea",{id:"payload",value:Q,onChange:s=>X(s.target.value),className:l("w-full p-4 rounded-xl bg-muted/40 font-mono text-sm resize-none h-32 transition-colors focus:outline-none focus:ring-1 focus:ring-primary/30",!de.valid&&"ring-1 ring-red-500"),placeholder:'{"url": "https://..."}'})]}),c==="advanced"&&e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 space-y-4",children:[e.jsxs("div",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2",children:[e.jsx(js,{className:"h-3.5 w-3.5"}),"Advanced Options"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(os,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:"Retry on failure"})]}),e.jsx("input",{type:"checkbox",checked:ie,onChange:s=>Ge(s.target.checked),className:"rounded"})]}),ie&&e.jsxs("div",{className:"grid grid-cols-2 gap-3 pl-6",children:[e.jsxs("div",{children:[e.jsx(g,{className:"text-xs",children:"Max Retries"}),e.jsx(C,{type:"number",min:1,max:10,value:Ee,onChange:s=>Qe(parseInt(s.target.value)||3),className:"mt-1 h-8 text-xs"})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs",children:"Backoff"}),e.jsxs("select",{value:Me,onChange:s=>We(s.target.value),className:"w-full mt-1 h-8 px-2 rounded-md border bg-background text-xs",children:[e.jsx("option",{value:"exponential",children:"Exponential"}),e.jsx("option",{value:"linear",children:"Linear"}),e.jsx("option",{value:"fixed",children:"Fixed"})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:"Send notifications"})]}),e.jsx("input",{type:"checkbox",checked:oe,onChange:s=>Be(s.target.checked),className:"rounded"})]}),oe&&e.jsxs("div",{className:"pl-6 space-y-2",children:[e.jsx(C,{placeholder:"Slack channel, webhook URL, or email",value:W,onChange:s=>Ve(s.target.value),className:"text-xs"}),e.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"checkbox",checked:Ye,onChange:s=>Xe(s.target.checked),className:"rounded"}),"On success"]}),e.jsxs("label",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"checkbox",checked:Ze,onChange:s=>es(s.target.checked),className:"rounded"}),"On failure"]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs(g,{className:"text-xs flex items-center gap-1",children:["Max Runs",e.jsx(Pe,{content:"Stop after N runs",children:e.jsx(De,{className:"h-3 w-3"})})]}),e.jsx(C,{type:"number",min:1,placeholder:"Unlimited",value:ce||"",onChange:s=>as(s.target.value?parseInt(s.target.value):null),className:"mt-1 h-8 text-xs"})]}),e.jsxs("div",{children:[e.jsxs(g,{className:"text-xs flex items-center gap-1",children:["Max Failures",e.jsx(Pe,{content:"Pause after N consecutive failures",children:e.jsx(De,{className:"h-3 w-3"})})]}),e.jsx(C,{type:"number",min:1,placeholder:"Unlimited",value:Re||"",onChange:s=>rs(s.target.value?parseInt(s.target.value):null),className:"mt-1 h-8 text-xs"})]})]})]})]}),d==="review"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-linear-to-br from-primary/20 to-primary/5 mb-3",children:e.jsx(G,{className:"h-8 w-8 text-primary"})}),e.jsx("h3",{className:"text-lg font-semibold",children:"Ready to Create"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Review your job configuration"})]}),e.jsxs("div",{className:"p-5 rounded-2xl bg-linear-to-br from-muted/50 to-transparent space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Job Name"}),e.jsx("div",{className:"text-lg font-semibold mt-1",children:w||"Untitled Job"}),k&&e.jsx("div",{className:"text-sm text-muted-foreground mt-0.5",children:k})]}),p&&e.jsx("div",{className:l("p-2 rounded-lg",p==="http"&&"bg-blue-500/20",p==="tool"&&"bg-indigo-500/20",p==="script"&&"bg-green-500/20",p==="message"&&"bg-orange-500/20"),children:te.find(s=>s.type===p)?.icon&&(()=>{const s=te.find(y=>y.type===p).icon;return e.jsx(s,{className:"h-5 w-5"})})()})]}),e.jsx("hr",{className:"border-border/50"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Type"}),e.jsx("div",{className:"text-sm font-medium mt-1",children:te.find(s=>s.type===p)?.label})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Schedule"}),e.jsx("div",{className:"text-sm font-medium mt-1",children:Es})]})]}),e.jsx("hr",{className:"border-border/50"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-2",children:"Payload"}),e.jsx("pre",{className:"p-3 rounded-lg bg-muted/50 text-xs font-mono overflow-x-auto max-h-24",children:Q})]}),c==="advanced"&&(ie||oe||ce||Re)&&e.jsxs(e.Fragment,{children:[e.jsx("hr",{className:"border-border/50"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ie&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-muted text-xs",children:[e.jsx(os,{className:"h-3 w-3"}),Ee,"x ",Me," retries"]}),oe&&W&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-muted text-xs",children:[e.jsx(Je,{className:"h-3 w-3"}),"Notify: ",W.slice(0,15),"..."]}),ce&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-muted text-xs",children:[e.jsx(As,{className:"h-3 w-3"}),"Max ",ce," runs"]})]})]})]}),p==="script"&&e.jsxs(_,{type:"warning",children:[e.jsx("strong",{children:"Security Notice:"})," Script jobs execute shell commands with server permissions. Ensure your command is safe before creating."]}),se.isError&&e.jsxs("div",{className:"flex items-center gap-2 p-4 rounded-xl bg-red-500/10 border border-red-500/20 text-red-500 text-sm",children:[e.jsx(we,{className:"h-5 w-5 shrink-0"}),e.jsx("span",{children:se.error instanceof Error?se.error.message:"Failed to create job"})]})]})]}),e.jsxs("div",{className:"border-t border-border/20 p-4 flex items-center justify-between bg-muted/30",children:[e.jsxs(D,{variant:"ghost",onClick:x===0?()=>N(!1):Ts,className:"gap-2",children:[e.jsx(Ps,{className:"h-4 w-4"}),x===0?"Cancel":"Back"]}),d==="review"?e.jsx(D,{onClick:()=>se.mutate(),disabled:se.isPending,className:"gap-2 min-w-35 shadow-lg shadow-primary/20",children:se.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qe,{className:"h-4 w-4"}),"Create Job"]})}):e.jsxs(D,{onClick:Ss,disabled:!Cs,className:"gap-2",children:["Continue",e.jsx(Fs,{className:"h-4 w-4"})]})]})]})]})}const Mt=[{value:"http",label:"HTTP Request",icon:Se},{value:"tool",label:"Tool Execution",icon:Y},{value:"script",label:"Shell Script",icon:ue},{value:"message",label:"Notification",icon:Ce}],Rt=[{label:"1 min",value:"* * * * *"},{label:"5 min",value:"*/5 * * * *"},{label:"15 min",value:"*/15 * * * *"},{label:"30 min",value:"*/30 * * * *"},{label:"Hourly",value:"0 * * * *"},{label:"Daily",value:"0 0 * * *"},{label:"Weekly",value:"0 0 * * 0"}];function Dt(t){return{"* * * * *":"Every minute","*/5 * * * *":"Every 5 minutes","*/15 * * * *":"Every 15 minutes","*/30 * * * *":"Every 30 minutes","0 * * * *":"Every hour","0 0 * * *":"Daily at midnight","0 0 * * 0":"Weekly on Sunday","0 9 * * 1-5":"Weekdays at 9 AM"}[t]||t}function At({type:t,children:o}){const f={info:{icon:Le,bg:"bg-blue-500/10",border:"border-blue-500/20",text:"text-blue-400"},warning:{icon:we,bg:"bg-amber-500/10",border:"border-amber-500/20",text:"text-amber-400"},tip:{icon:Le,bg:"bg-green-500/10",border:"border-green-500/20",text:"text-green-400"}},{icon:i,bg:j,border:h,text:N}=f[t];return e.jsxs("div",{className:l("flex items-start gap-2 p-3 rounded-lg border text-xs",j,h,N),children:[e.jsx(i,{className:"h-4 w-4 shrink-0 mt-0.5"}),e.jsx("div",{children:o})]})}function Pt({job:t,open:o,onOpenChange:f}){const i=ze(),[j,h]=r.useState(""),[N,c]=r.useState(""),[b,d]=r.useState("cron"),[m,x]=r.useState("*/5 * * * *"),[u,P]=r.useState(300),[w,L]=r.useState("{}"),[k,F]=r.useState([]),[p,$]=r.useState(""),[v,E]=r.useState("active");r.useEffect(()=>{t&&(h(t.name),c(t.description||""),d(t.cronExpression?"cron":"interval"),x(t.cronExpression||"*/5 * * * *"),P(t.intervalMs?Math.round(t.intervalMs/1e3):300),L(JSON.stringify(t.payload||{},null,2)),F(t.labels||[]),E(t.status==="paused"?"paused":"active"))},[t]);const M=K({mutationFn:()=>{if(!t)throw new Error("No job to update");const n=JSON.parse(w);return O.cron.update(t.id,{name:j,description:N||void 0,cronExpression:b==="cron"?m:void 0,intervalMs:b==="interval"?u*1e3:void 0,payload:n,labels:k,status:v})},onSuccess:()=>{i.invalidateQueries({queryKey:["cron-jobs"]}),i.invalidateQueries({queryKey:["cron-stats"]}),f(!1)}}),q=j.trim().length>0&&(b==="cron"&&m.trim().length>0||b==="interval"&&u>=1),A=()=>{const n=p.trim().toLowerCase();n&&!k.includes(n)&&(F([...k,n]),$(""))},H=n=>{F(k.filter(R=>R!==n))};if(!t)return null;const T=Mt.find(n=>n.value===t.jobType)?.icon||Y;return e.jsx($e,{open:o,onOpenChange:f,children:e.jsxs(He,{className:"max-w-2xl max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsx(Ue,{children:e.jsxs(Ke,{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(T,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"block",children:"Edit Scheduled Job"}),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:[t.jobType.toUpperCase()," • Created ",new Date(t.createdAt).toLocaleDateString()]})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"name",children:"Job Name"}),e.jsx(C,{id:"name",value:j,onChange:n=>h(n.target.value),placeholder:"My Scheduled Job",className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"description",children:"Description (optional)"}),e.jsx(C,{id:"description",value:N,onChange:n=>c(n.target.value),placeholder:"What this job does...",className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2 block",children:"Status"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>E("active"),className:l("flex items-center gap-2 px-4 py-2 rounded-xl border transition-all",v==="active"?"border-green-500/50 bg-green-500/10 text-green-500":"border-border/50 hover:border-border"),children:[e.jsx(ke,{className:"h-4 w-4"}),"Active"]}),e.jsxs("button",{onClick:()=>E("paused"),className:l("flex items-center gap-2 px-4 py-2 rounded-xl border transition-all",v==="paused"?"border-amber-500/50 bg-amber-500/10 text-amber-500":"border-border/50 hover:border-border"),children:[e.jsx(ge,{className:"h-4 w-4"}),"Paused"]})]})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2 block",children:"Schedule"}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsxs("button",{onClick:()=>d("cron"),className:l("flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-all",b==="cron"?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:[e.jsx(J,{className:"h-4 w-4"}),"Cron"]}),e.jsxs("button",{onClick:()=>d("interval"),className:l("flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-all",b==="interval"?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:[e.jsx(pe,{className:"h-4 w-4"}),"Interval"]})]}),b==="cron"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(C,{value:m,onChange:n=>x(n.target.value),placeholder:"*/5 * * * *",className:"font-mono"}),e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(ke,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:Dt(m)})]})})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Rt.map(n=>e.jsx("button",{onClick:()=>x(n.value),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",m===n.value?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:n.label},n.value))})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Every"}),e.jsx(C,{type:"number",min:1,value:u,onChange:n=>P(parseInt(n.target.value)||60),className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"seconds"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[30,60,300,600,1800,3600].map(n=>e.jsx("button",{onClick:()=>P(n),className:l("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",u===n?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80"),children:n<60?`${n}s`:n<3600?`${n/60}m`:`${n/3600}h`},n))})]})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2 block",children:"Labels"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:k.map(n=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-lg bg-primary/10 text-primary text-xs",children:[e.jsx(vs,{className:"h-3 w-3"}),n,e.jsx("button",{onClick:()=>H(n),className:"ml-1 hover:text-red-500",children:e.jsx(Is,{className:"h-3 w-3"})})]},n))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{value:p,onChange:n=>$(n.target.value),placeholder:"Add label...",className:"flex-1",onKeyDown:n=>n.key==="Enter"&&(n.preventDefault(),A())}),e.jsx(D,{variant:"outline",size:"sm",onClick:A,disabled:!p.trim(),children:e.jsx(fs,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"payload",children:"Payload (JSON)"}),e.jsx("textarea",{id:"payload",value:w,onChange:n=>L(n.target.value),rows:6,className:"w-full mt-1.5 px-3 py-2 rounded-lg border border-border bg-background font-mono text-sm resize-none focus:outline-none focus:ring-2 focus:ring-primary/50"}),e.jsx(At,{type:"info",children:"Payload is specific to job type. HTTP jobs need url/method, tool jobs need tool/params."})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsx(D,{variant:"ghost",onClick:()=>f(!1),children:"Cancel"}),e.jsx(D,{onClick:()=>M.mutate(),disabled:!q||M.isPending,className:"gap-2",children:M.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ws,{className:"h-4 w-4"}),"Save Changes"]})})]}),M.isError&&e.jsxs("div",{className:"mt-2 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm",children:[e.jsx(we,{className:"h-4 w-4 inline mr-2"}),M.error.message]})]})})}const xs=[{value:"all",label:"All Status",icon:J},{value:"active",label:"Active",icon:G},{value:"paused",label:"Paused",icon:ge},{value:"completed",label:"Completed",icon:G},{value:"failed",label:"Failed",icon:ae},{value:"archived",label:"Archived",icon:_e}],us=[{value:"all",label:"All Types",icon:Te},{value:"http",label:"HTTP",icon:Se},{value:"tool",label:"Tool",icon:Y},{value:"script",label:"Script",icon:ue},{value:"message",label:"Message",icon:Ce}];function na(){const t=ze(),[o,f]=r.useState(""),[i,j]=r.useState("all"),[h,N]=r.useState("all"),[c,b]=r.useState(null),[d,m]=r.useState(""),[x,u]=r.useState(null),[P,w]=r.useState(null),{data:L,isLoading:k,error:F,refetch:p}=Ne({queryKey:["cron-jobs",i,h],queryFn:()=>O.cron.list({status:i!=="all"?i:void 0,jobType:h!=="all"?h:void 0,limit:100}),refetchInterval:1e4}),{data:$}=Ne({queryKey:["cron-stats"],queryFn:()=>O.cron.stats(),refetchInterval:3e4}),v=L?.jobs||[],E=$?.stats,M=v.filter(a=>o?a.name.toLowerCase().includes(o.toLowerCase())||a.description?.toLowerCase().includes(o.toLowerCase()):!0),q=K({mutationFn:a=>O.cron.trigger(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]})}}),A=K({mutationFn:a=>O.cron.pause(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),H=K({mutationFn:a=>O.cron.resume(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),T=K({mutationFn:a=>O.cron.delete(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]}),u(null)}}),n=K({mutationFn:a=>O.cron.archive(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),R=K({mutationFn:a=>O.cron.restore(a),onSuccess:()=>{t.invalidateQueries({queryKey:["cron-jobs"]}),t.invalidateQueries({queryKey:["cron-stats"]})}}),fe=r.useCallback(a=>{q.mutate(a)},[q]),U=r.useCallback(a=>{A.mutate(a)},[A]),be=r.useCallback(a=>{H.mutate(a)},[H]),ve=r.useCallback(a=>{b(a.id),m(a.name)},[]),je=r.useCallback(a=>{u(a)},[]),Q=r.useCallback(a=>{w(a)},[]),X=r.useCallback(a=>{n.mutate(a)},[n]),I=r.useCallback(a=>{R.mutate(a)},[R]),Z=()=>{x&&T.mutate(x)};return F?e.jsxs("div",{className:"glass rounded-[28px] p-12 text-center",children:[e.jsx(he,{className:"h-12 w-12 mx-auto text-red-400 mb-4"}),e.jsx("p",{className:"text-lg font-bold text-red-400",children:"Error loading scheduled jobs"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:F.message}),e.jsxs(D,{variant:"outline",onClick:()=>p(),className:"mt-4",children:[e.jsx(re,{className:"h-4 w-4 mr-2"}),"Retry"]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("header",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-bold tracking-tight flex items-center gap-2",children:[e.jsx(J,{className:"h-6 w-6 text-primary"}),"Scheduled Jobs"]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage automated tasks with cron schedules or fixed intervals"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>p(),disabled:k,children:[e.jsx(re,{className:l("h-4 w-4 mr-2",k&&"animate-spin")}),"Refresh"]}),e.jsx(ms,{})]})]}),E&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4",children:[e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Total Jobs"})]}),e.jsx("div",{className:"text-2xl font-bold",children:E.total})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-500 mb-1",children:[e.jsx(ps,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Active"})]}),e.jsx("div",{className:"text-2xl font-bold text-green-500",children:E.active})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-500 mb-1",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Paused"})]}),e.jsx("div",{className:"text-2xl font-bold text-amber-500",children:E.paused})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(xe,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Total Runs"})]}),e.jsx("div",{className:"text-2xl font-bold",children:E.totalRuns})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-500 mb-1",children:[e.jsx(tt,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Successes"})]}),e.jsx("div",{className:"text-2xl font-bold text-green-500",children:E.totalSuccesses})]}),e.jsxs("div",{className:"glass rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-500 mb-1",children:[e.jsx(ae,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Failures"})]}),e.jsx("div",{className:"text-2xl font-bold text-red-500",children:E.totalFailures})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[e.jsx(Os,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(C,{placeholder:"Search jobs...",value:o,onChange:a=>f(a.target.value),className:"pl-10 bg-white/5 border-white/10 rounded-xl"})]}),e.jsxs(Fe,{children:[e.jsx(Ie,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(at,{className:"h-4 w-4"}),xs.find(a=>a.value===i)?.label]})}),e.jsx(Oe,{align:"start",children:xs.map(a=>{const ee=a.icon;return e.jsxs(z,{onClick:()=>j(a.value),className:l(i===a.value&&"bg-primary/10"),children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),a.label]},a.value)})})]}),e.jsxs(Fe,{children:[e.jsx(Ie,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(gs,{className:"h-4 w-4"}),us.find(a=>a.value===h)?.label]})}),e.jsx(Oe,{align:"start",children:us.map(a=>{const ee=a.icon;return e.jsxs(z,{onClick:()=>N(a.value),className:l(h===a.value&&"bg-primary/10"),children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),a.label]},a.value)})})]})]}),k?e.jsxs("div",{className:"glass rounded-[28px] p-12 flex flex-col items-center justify-center",children:[e.jsx(ne,{className:"h-8 w-8 animate-spin text-primary mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading scheduled jobs..."})]}):M.length===0?e.jsxs("div",{className:"glass rounded-[28px] p-12 text-center",children:[e.jsx(J,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-1",children:o||i!=="all"||h!=="all"?"No jobs match your filters":"No scheduled jobs yet"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:o||i!=="all"||h!=="all"?"Try adjusting your search or filters":"Create your first scheduled job to automate tasks"}),!(o||i!=="all"||h!=="all")&&e.jsx(ms,{})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:M.map(a=>e.jsx(vt,{job:a,onTrigger:fe,onPause:U,onResume:be,onDelete:je,onViewHistory:()=>ve(a),onEdit:Q,onArchive:X,onRestore:I},a.id))}),e.jsx(kt,{jobId:c,jobName:d,open:!!c,onOpenChange:a=>!a&&b(null)}),e.jsx(Pt,{job:P,open:!!P,onOpenChange:a=>!a&&w(null)}),e.jsx(Js,{open:!!x,onOpenChange:a=>!a&&u(null),children:e.jsxs(Ls,{children:[e.jsxs(zs,{children:[e.jsx(qs,{children:"Delete Scheduled Job?"}),e.jsx(_s,{children:"This will permanently delete this job and all its run history. This action cannot be undone."})]}),e.jsxs($s,{children:[e.jsx(Hs,{children:"Cancel"}),e.jsx(Us,{onClick:Z,className:"bg-red-500 hover:bg-red-600",disabled:T.isPending,children:T.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):"Delete Job"})]})]})})]})}export{ms as CreateJobModal,na as CronDashboard,Pt as EditJobModal,vt as JobCard,kt as JobHistoryModal};
|