(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[15962],{378:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>p});var r=n(95155),s=n(64577),a=n(99314),c=n(81402),o=n(73321),l=n(12115),u=n(3765),i=n(98757),d=n(45160),f=n(89239),m=n(60529);let h=`---
description: What this skill does
---

Your skill instructions here. Use $ARGUMENTS for user input.
`;function p({params:e}){let{name:t}=(0,l.use)(e),n=(0,o.useSearchParams)(),x=(0,o.useRouter)(),v="new"===t,g=n.get("scope")||"user",w=n.get("cwd")||void 0;(0,u.si)(v?"New Skill":"Edit Skill");let[k,y]=(0,l.useState)(v?"":decodeURIComponent(t)),[b,N]=(0,l.useState)(v?h:""),[S,j]=(0,l.useState)(v?h:""),[C,E]=(0,l.useState)(!v),[R,$]=(0,l.useState)(!1),[L,U]=(0,l.useState)(null),[_,z]=(0,l.useState)(!1),O=b!==S;(0,l.useEffect)(()=>{if(v)return;let e=new URLSearchParams({scope:g});w&&e.set("cwd",w),fetch(`/api/skills/${encodeURIComponent(t)}?${e}`).then(e=>{if(!e.ok)throw Error("Not found");return e.json()}).then(e=>{N(e.content),j(e.content)}).catch(()=>{U("Failed to load skill")}).finally(()=>E(!1))},[v,t,g,w]);let P=(0,l.useCallback)(async()=>{let e=k.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/skills/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:g,cwd:w,content:b})})).ok)throw Error("Save failed");if(j(b),U("Saved"),v){let t=new URLSearchParams({scope:g});w&&t.set("cwd",w),x.replace(`/skills/${encodeURIComponent(e)}?${t}`)}}catch{U("Failed to save")}finally{$(!1)}},[k,b,g,w,v,x]);return C?(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)(m.p,{placeholder:"skill-name",value:k,onChange:e=>y(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:k}),(0,r.jsx)(d.E,{variant:"secondary",children:"user"===g?"Global":"Project"})]})}),(0,r.jsxs)(f.$,{size:"sm",variant:"outline",onClick:()=>{let e=document.createElement("textarea");e.value=b,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)(f.$,{size:"sm",onClick:P,disabled:R||!v&&!O,children:[(0,r.jsx)(c.A,{className:"h-4 w-4 mr-1"}),R?"Saving...":"Save"]})]}),L&&(0,r.jsx)("p",{className:`text-sm ${"Saved"===L?"text-green-600":"text-destructive"}`,children:L}),(0,r.jsx)(i.B,{value:b,onChange:N,language:"markdown",onSave:P,className:"flex-1"})]})}},24922:(e,t,n)=>{Promise.resolve().then(n.bind(n,378))},98757:(e,t,n)=>{"use strict";n.d(t,{B:()=>h});var r=n(95155),s=n(13748),a=n(53649),c=n(27071),o=n(74059),l=n(89561),u=n(62465),i=n(12115);let d=l.Lz.theme({"&":{backgroundColor:"transparent"},".cm-gutters":{backgroundColor:"transparent",borderRight:"1px solid hsl(var(--border))"}});function f(){return!("u"<typeof document)&&document.documentElement.classList.contains("dark")}function m(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,i.useRef)(null),v=(0,i.useRef)(null),g=(0,i.useRef)(new c.xx),w=(0,i.useRef)(new c.xx),k=(0,i.useRef)(new c.xx),y=(0,i.useRef)(t),b=(0,i.useRef)(p),N=(0,i.useRef)(e);return y.current=t,b.current=p,(0,i.useEffect)(()=>{if(!x.current)return;let e=c.$t.create({doc:N.current,extensions:[u.oQ,l.Lz.lineWrapping,g.current.of(f()?o.bM:d),w.current.of(m(n)),k.current.of(c.$t.readOnly.of(!!s)),l.w4.of([{key:"Mod-s",run:()=>(b.current?.(),!0)}]),l.Lz.updateListener.of(e=>{if(e.docChanged){let t=e.state.doc.toString();N.current=t,y.current(t)}})]}),t=new l.Lz({state:e,parent:x.current});return v.current=t,()=>{t.destroy(),v.current=null}},[]),(0,i.useEffect)(()=>{let t=v.current;t&&e!==N.current&&(N.current=e,t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}}))},[e]),(0,i.useEffect)(()=>{let e=v.current;if(!e)return;let t=new MutationObserver(()=>{e.dispatch({effects:g.current.reconfigure(f()?o.bM:d)})});return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,i.useEffect)(()=>{let e=v.current;e&&e.dispatch({effects:w.current.reconfigure(m(n))})},[n]),(0,i.useEffect)(()=>{let e=v.current;e&&e.dispatch({effects:k.current.reconfigure(c.$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=24922)),_N_E=e.O()}]);