(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[36994],{56905:(e,t,n)=>{"use strict";n.d(t,{n:()=>u});var r=n(95155),s=n(18986),o=n(25182),a=n(12115),c=n(98757),l=n(64233),i=n(40980);let d="cockpit-md-editor-preview";function u({value:e,onChange:t,onSave:n,className:f}){let[h,x]=(0,a.useState)(!1);(0,a.useEffect)(()=>{"1"===localStorage.getItem(d)&&x(!0)},[]);let p=(0,a.useCallback)(e=>{x(e),localStorage.setItem(d,e?"1":"0")},[]);return(0,r.jsxs)("div",{className:(0,i.cn)("flex flex-col min-h-0 overflow-hidden rounded-md border bg-background",f),children:[(0,r.jsxs)("div",{className:"shrink-0 flex items-center gap-1 border-b bg-muted/30 px-2 py-1",children:[(0,r.jsx)(m,{active:!h,icon:(0,r.jsx)(s.A,{className:"h-3.5 w-3.5"}),label:"Edit",onClick:()=>p(!1)}),(0,r.jsx)(m,{active:h,icon:(0,r.jsx)(o.A,{className:"h-3.5 w-3.5"}),label:"Preview",onClick:()=>p(!0)})]}),h?(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:e.trim()?(0,r.jsx)(l.Y,{content:e}):(0,r.jsx)("p",{className:"text-sm text-muted-foreground italic",children:"Nothing to preview."})}):(0,r.jsx)(c.B,{value:e,onChange:t,language:"markdown",onSave:n,className:"flex-1 min-h-0 rounded-none border-0 [&_.cm-editor]:h-full [&_.cm-editor]:min-h-[300px]"})]})}function m({active:e,icon:t,label:n,onClick:s}){return(0,r.jsxs)("button",{type:"button",onClick:s,"aria-pressed":e,className:(0,i.cn)("inline-flex items-center gap-1.5 rounded px-2 py-0.5 text-xs transition-colors",e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[t,n]})}},96326:(e,t,n)=>{Promise.resolve().then(n.bind(n,98334))},98334:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>x});var r=n(95155),s=n(64577),o=n(99314),a=n(81402),c=n(73321),l=n(12115),i=n(1550),d=n(56905),u=n(45160),m=n(89239),f=n(60529);let h=`---
description: What this command does
---

Your command prompt here. Use $ARGUMENTS for user input.
`;function x({params:e}){let{name:t}=(0,l.use)(e),n=(0,c.useSearchParams)(),p=(0,c.useRouter)(),v="new"===t,g=n.get("scope")||"user",b=n.get("cwd")||void 0;(0,i.si)(v?"New Command":"Edit Command",{hideActions:!0});let[w,N]=(0,l.useState)(v?"":decodeURIComponent(t)),[j,y]=(0,l.useState)(v?h:""),[C,k]=(0,l.useState)(v?h:""),[S,E]=(0,l.useState)(!v),[R,$]=(0,l.useState)(!1),[_,L]=(0,l.useState)(null),[U,A]=(0,l.useState)(!1),z=j!==C;(0,l.useEffect)(()=>{if(v)return;let e=new URLSearchParams({scope:g});b&&e.set("cwd",b),fetch(`/api/commands/${encodeURIComponent(t)}?${e}`).then(e=>{if(!e.ok)throw Error("Not found");return e.json()}).then(e=>{y(e.content),k(e.content)}).catch(()=>{L("Failed to load command")}).finally(()=>E(!1))},[v,t,g,b]);let P=(0,l.useCallback)(async()=>{let e=w.trim();if(!e)return void L("Name is required");if(!/^[a-zA-Z0-9_-]+$/.test(e))return void L("Name can only contain letters, numbers, hyphens, and underscores");$(!0),L(null);try{if(!(await fetch(`/api/commands/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:g,cwd:b,content:j})})).ok)throw Error("Save failed");if(k(j),L("Saved"),v){let t=new URLSearchParams({scope:g});b&&t.set("cwd",b),p.replace(`/commands/${encodeURIComponent(e)}?${t}`)}}catch{L("Failed to save")}finally{$(!1)}},[w,j,g,b,v,p]);return S?(0,r.jsx)("div",{className:"flex-1 min-h-0 p-4",children:(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading..."})}):(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("div",{className:"flex-1 min-w-0",children:v?(0,r.jsx)(f.p,{placeholder:"command-name",value:w,onChange:e=>N(e.target.value),className:"font-mono"}):(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"font-mono font-bold text-lg",children:w}),(0,r.jsx)(u.E,{variant:"secondary",children:"user"===g?"Global":"Project"})]})}),(0,r.jsxs)(m.$,{size:"sm",variant:"outline",onClick:()=>{let e=document.createElement("textarea");e.value=j,e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),A(!0),setTimeout(()=>A(!1),1500)},children:[U?(0,r.jsx)(s.A,{className:"h-4 w-4 mr-1"}):(0,r.jsx)(o.A,{className:"h-4 w-4 mr-1"}),U?"Copied":"Copy"]}),(0,r.jsxs)(m.$,{size:"sm",onClick:P,disabled:R||!v&&!z,children:[(0,r.jsx)(a.A,{className:"h-4 w-4 mr-1"}),R?"Saving...":"Save"]})]}),_&&(0,r.jsx)("p",{className:`text-sm ${"Saved"===_?"text-green-600":"text-destructive"}`,children:_}),(0,r.jsx)(d.n,{value:j,onChange:y,onSave:P,className:"flex-1 min-h-0"})]})}},98757:(e,t,n)=>{"use strict";n.d(t,{B:()=>h});var r=n(95155),s=n(13748),o=n(53649),a=n(27071),c=n(74059),l=n(89561),i=n(62465),d=n(12115);let u=l.Lz.theme({"&":{backgroundColor:"transparent"},".cm-gutters":{backgroundColor:"transparent",borderRight:"1px solid hsl(var(--border))"}});function m(){return!("u"<typeof document)&&document.documentElement.classList.contains("dark")}function f(e){switch(e){case"markdown":default:return(0,s.wD)();case"yaml":return(0,o.oQ)()}}function h({value:e,onChange:t,language:n,readOnly:s,className:o,onSave:x}){let p=(0,d.useRef)(null),v=(0,d.useRef)(null),g=(0,d.useRef)(new a.xx),b=(0,d.useRef)(new a.xx),w=(0,d.useRef)(new a.xx),N=(0,d.useRef)(t),j=(0,d.useRef)(x),y=(0,d.useRef)(e);return N.current=t,j.current=x,(0,d.useEffect)(()=>{if(!p.current)return;let e=a.$t.create({doc:y.current,extensions:[i.oQ,l.Lz.lineWrapping,g.current.of(m()?c.bM:u),b.current.of(f(n)),w.current.of(a.$t.readOnly.of(!!s)),l.w4.of([{key:"Mod-s",run:()=>(j.current?.(),!0)}]),l.Lz.updateListener.of(e=>{if(e.docChanged){let t=e.state.doc.toString();y.current=t,N.current(t)}})]}),t=new l.Lz({state:e,parent:p.current});return v.current=t,()=>{t.destroy(),v.current=null}},[]),(0,d.useEffect)(()=>{let t=v.current;t&&e!==y.current&&(y.current=e,t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}}))},[e]),(0,d.useEffect)(()=>{let e=v.current;if(!e)return;let t=new MutationObserver(()=>{e.dispatch({effects:g.current.reconfigure(m()?c.bM:u)})});return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,d.useEffect)(()=>{let e=v.current;e&&e.dispatch({effects:b.current.reconfigure(f(n))})},[n]),(0,d.useEffect)(()=>{let e=v.current;e&&e.dispatch({effects:w.current.reconfigure(a.$t.readOnly.of(!!s))})},[s]),(0,r.jsx)("div",{ref:p,className:`overflow-auto rounded-md border bg-background text-sm [&_.cm-editor]:min-h-[200px] [&_.cm-editor.cm-focused]:outline-none ${o||""}`})}}},e=>{e.O(0,[6079,989,25781,6802,1550,28441,93794,77358],()=>e(e.s=96326)),_N_E=e.O()}]);