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