(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[96494],{36456:(e,s,n)=>{"use strict";n.r(s),n.d(s,{default:()=>x});var t=n(95155),a=n(2125),c=n(65738),l=n(73321),o=n(12115),r=n(3765),i=n(45160),d=n(89239),m=n(81477),u=n(42763);function x(){(0,r.si)("Commands");let e="u">typeof localStorage&&localStorage.getItem("cockpit-agents-cwd")||void 0,{commands:s,loading:n,deleteCommand:c}=function(e){let[s,n]=(0,o.useState)([]),[t,a]=(0,o.useState)(!0),c=(0,o.useCallback)(()=>{a(!0);let s=new URLSearchParams;e&&s.set("cwd",e),fetch(`/api/commands?${s}`).then(e=>e.json()).then(e=>n(e.commands)).catch(()=>n([])).finally(()=>a(!1))},[e]);(0,o.useEffect)(()=>{c()},[c]);let l=(0,o.useCallback)(async(s,n)=>{let t=new URLSearchParams({scope:n});"project"===n&&e&&t.set("cwd",e);try{if((await fetch(`/api/commands/${encodeURIComponent(s)}?${t}`,{method:"DELETE"})).ok)return c(),!0;return!1}catch{return!1}},[e,c]);return{commands:s,loading:t,refresh:c,deleteCommand:l}}(e),i=(0,l.useRouter)(),[x,p]=(0,o.useState)(null),[j,f]=(0,o.useState)(!1),N=s.filter(e=>"user"===e.scope),C=s.filter(e=>"project"===e.scope);function b(s){f(!1);let n=new URLSearchParams({scope:s});"project"===s&&e&&n.set("cwd",e),i.push(`/commands/new?${n}`)}function g(s,n){let t=new URLSearchParams({scope:n});"project"===n&&e&&t.set("cwd",e),i.push(`/commands/${encodeURIComponent(s)}?${t}`)}async function v(){x&&(await c(x.name,x.scope),p(null))}return(0,t.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-4",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("div",{}),(0,t.jsxs)(d.$,{size:"sm",onClick:()=>f(!0),children:[(0,t.jsx)(a.A,{className:"h-4 w-4 mr-1"}),"New Command"]})]}),n&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading commands..."}),!n&&0===s.length&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No custom commands found. Create one to get started."}),N.length>0&&(0,t.jsxs)(m.Zp,{children:[(0,t.jsx)(m.aR,{children:(0,t.jsx)(m.ZB,{className:"text-base",children:"Global"})}),(0,t.jsx)(m.Wu,{className:"space-y-1",children:N.map(e=>(0,t.jsx)(h,{name:e.name,scope:"user",description:e.description,onClick:()=>g(e.name,"user"),onDelete:()=>p({name:e.name,scope:"user"})},e.name))})]}),C.length>0&&(0,t.jsxs)(m.Zp,{children:[(0,t.jsx)(m.aR,{children:(0,t.jsx)(m.ZB,{className:"text-base",children:"Project"})}),(0,t.jsx)(m.Wu,{className:"space-y-1",children:C.map(e=>(0,t.jsx)(h,{name:e.name,scope:"project",description:e.description,onClick:()=>g(e.name,"project"),onDelete:()=>p({name:e.name,scope:"project"})},e.name))})]}),(0,t.jsx)(u.lG,{open:j,onOpenChange:f,children:(0,t.jsxs)(u.Cf,{children:[(0,t.jsx)(u.c7,{children:(0,t.jsx)(u.L3,{children:"New Command"})}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"Where should this command be saved?"}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.$,{variant:"outline",className:"flex-1",onClick:()=>b("user"),children:"Global"}),(0,t.jsx)(d.$,{variant:"outline",className:"flex-1",onClick:()=>b("project"),disabled:!e,children:"Project"})]})]})}),(0,t.jsx)(u.lG,{open:!!x,onOpenChange:()=>p(null),children:(0,t.jsxs)(u.Cf,{children:[(0,t.jsx)(u.c7,{children:(0,t.jsx)(u.L3,{children:"Delete Command"})}),(0,t.jsxs)("p",{className:"text-sm text-muted-foreground mb-4",children:["Delete ",(0,t.jsx)("span",{className:"font-mono font-bold",children:x?.name}),"? This cannot be undone."]}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(d.$,{variant:"outline",onClick:()=>p(null),children:"Cancel"}),(0,t.jsx)(d.$,{variant:"destructive",onClick:v,children:"Delete"})]})]})})]})}function h({name:e,scope:s,description:n,onClick:a,onDelete:l}){return(0,t.jsxs)("div",{className:"flex items-center gap-3 rounded px-2 py-2 hover:bg-muted transition-colors",children:[(0,t.jsxs)("button",{type:"button",className:"flex-1 text-left min-w-0",onClick:a,children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"font-mono font-bold text-sm",children:e}),(0,t.jsx)(i.E,{variant:"secondary",className:"text-[10px]",children:"user"===s?"Global":"Project"})]}),n&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:n})]}),(0,t.jsx)("button",{type:"button",className:"shrink-0 p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",onClick:e=>{e.stopPropagation(),l()},children:(0,t.jsx)(c.A,{className:"h-4 w-4"})})]})}},89850:(e,s,n)=>{Promise.resolve().then(n.bind(n,36456))}},e=>{e.O(0,[989,11242,3765,28441,93794,77358],()=>e(e.s=89850)),_N_E=e.O()}]);