import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{Q as r,X as i,at as a,b as o,i as s,it as c,nt as l,x as u,y as d}from"./vendor-mui-Ckcy4Lfd.js";import{J as f,a as p}from"./vendor-mui-icons-606Bohdn.js";import{a as m,c as h,g,o as _,s as v,t as y,v as b}from"./ui-BLXHSX1T.js";var x=e(n(),1),S=t();function C({skill:e,onSubmit:t,onCancel:n,submitLabel:C=`Save`}){let[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)([``]),[A,j]=(0,x.useState)([]),[M,N]=(0,x.useState)([]),[P,F]=(0,x.useState)([]),[I,L]=(0,x.useState)([]),[R,z]=(0,x.useState)(`user`),[B,V]=(0,x.useState)(1),[H,U]=(0,x.useState)(!1),[W,G]=(0,x.useState)(!1);(0,x.useEffect)(()=>{e&&(T(e.title),D(e.description),k(e.steps.length>0?e.steps:[``]),j(e.triggers??[]),N(e.inputHints??[]),F(e.filePatterns??[]),L(e.tags??[]),z(e.source),V(e.confidence))},[e]);let K=async()=>{if(!w.trim()){G(!0);return}U(!0);try{await t({title:w.trim(),description:E.trim(),steps:O.map(e=>e.trim()).filter(Boolean),triggers:A,inputHints:M,filePatterns:P,tags:I,source:R,confidence:B})}finally{U(!1)}},q=(e,t)=>{k(n=>n.map((n,r)=>r===e?t:n))},J=()=>{k(e=>[...e,``])},Y=e=>{k(t=>t.filter((t,n)=>n!==e))};return(0,S.jsxs)(r,{component:`form`,id:`skill-form`,onSubmit:e=>{e.preventDefault(),K()},sx:{display:`flex`,flexDirection:`column`,gap:3},children:[(0,S.jsx)(m,{main:(0,S.jsxs)(r,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,S.jsx)(_,{fieldLabel:`Title`,required:!0,autoFocus:!0,fullWidth:!0,value:w,onChange:e=>{T(e.target.value),G(!1)},error:W,helperText:W?`Title is required`:void 0}),(0,S.jsxs)(r,{children:[(0,S.jsx)(v,{children:`Description`}),(0,S.jsx)(y,{value:E,onChange:D,height:200})]}),(0,S.jsx)(b,{title:`Steps`,children:(0,S.jsxs)(r,{sx:{display:`flex`,flexDirection:`column`,gap:1},children:[O.map((e,t)=>(0,S.jsxs)(r,{sx:{display:`flex`,gap:1,alignItems:`center`},children:[(0,S.jsxs)(l,{variant:`body2`,sx:{minWidth:24,color:`text.secondary`},children:[t+1,`.`]}),(0,S.jsx)(s,{fullWidth:!0,size:`small`,value:e,onChange:e=>q(t,e.target.value),placeholder:`Step ${t+1}`}),O.length>1&&(0,S.jsx)(c,{size:`small`,onClick:()=>Y(t),color:`error`,children:(0,S.jsx)(p,{fontSize:`small`})})]},t)),(0,S.jsx)(i,{size:`small`,startIcon:(0,S.jsx)(f,{}),onClick:J,sx:{alignSelf:`flex-start`},children:`Add Step`})]})}),(0,S.jsx)(b,{title:`Matching`,children:(0,S.jsxs)(r,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,S.jsxs)(h,{fullWidth:!0,children:[(0,S.jsx)(v,{children:`Triggers`}),(0,S.jsx)(g,{tags:A,editable:!0,onAdd:e=>j(t=>t.includes(e)?t:[...t,e]),onRemove:e=>j(t=>t.filter(t=>t!==e))})]}),(0,S.jsxs)(h,{fullWidth:!0,children:[(0,S.jsx)(v,{children:`Input Hints`}),(0,S.jsx)(g,{tags:M,editable:!0,onAdd:e=>N(t=>t.includes(e)?t:[...t,e]),onRemove:e=>N(t=>t.filter(t=>t!==e))})]}),(0,S.jsxs)(h,{fullWidth:!0,children:[(0,S.jsx)(v,{children:`File Patterns`}),(0,S.jsx)(g,{tags:P,editable:!0,onAdd:e=>F(t=>t.includes(e)?t:[...t,e]),onRemove:e=>F(t=>t.filter(t=>t!==e))})]})]})})]}),sidebar:(0,S.jsxs)(r,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,S.jsxs)(h,{children:[(0,S.jsx)(v,{children:`Source`}),(0,S.jsxs)(o,{fullWidth:!0,value:R,onChange:e=>z(e.target.value),children:[(0,S.jsx)(u,{value:`user`,children:`User`}),(0,S.jsx)(u,{value:`learned`,children:`Learned`})]})]}),(0,S.jsx)(h,{children:(0,S.jsxs)(r,{sx:{px:1},children:[(0,S.jsxs)(v,{children:[`Confidence: `,Math.round(B*100),`%`]}),(0,S.jsx)(d,{value:B,onChange:(e,t)=>V(t),min:0,max:1,step:.01,valueLabelDisplay:`auto`,valueLabelFormat:e=>`${Math.round(e*100)}%`})]})}),(0,S.jsxs)(h,{fullWidth:!0,children:[(0,S.jsx)(v,{children:`Tags`}),(0,S.jsx)(g,{tags:I,editable:!0,onAdd:e=>L(t=>t.includes(e)?t:[...t,e]),onRemove:e=>L(t=>t.filter(t=>t!==e))})]})]})}),(0,S.jsxs)(r,{sx:{display:`flex`,gap:1,justifyContent:`flex-end`},children:[(0,S.jsx)(i,{onClick:n,children:`Cancel`}),(0,S.jsx)(i,{variant:`contained`,onClick:K,disabled:H||!w.trim(),children:H?(0,S.jsx)(a,{size:20}):C})]})]})}export{C as t};