import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{c as r,l as i,u as a}from"./vendor-react-Cts2Wj-s.js";import{N as o,Q as s,X as c,at as l,g as u,i as d,it as f,rt as p}from"./vendor-mui-Ckcy4Lfd.js";import"./vendor-md-editor-DC6xr_29.js";import{$ as m,J as h,ft as g,lt as _}from"./vendor-mui-icons-606Bohdn.js";import{f as v,i as y,p as b,u as x,x as S}from"./ui-BLXHSX1T.js";import{V as C}from"./index-JB73_g7R.js";import{t as w}from"./usePagination-DY41LU0X.js";import{a as T,g as E,m as D,p as O,s as k,t as A}from"./skill-ZS39xCGU.js";import"./SkillForm-BXiqw4Of.js";var j=e(n(),1);function M(e,t=25){let[n,r]=(0,j.useState)([]),[i,a]=(0,j.useState)(!1),[o,s]=(0,j.useState)(null),{page:c,setPage:l,total:u,setTotal:d,totalPages:f,offset:p}=w(t),m=(0,j.useCallback)(async()=>{if(e){a(!0),s(null);try{let{items:n,total:i}=await O(e,{limit:t,offset:p});r(n),d(i)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}}},[e,t,p,d]);return(0,j.useEffect)(()=>{m()},[m]),{skills:n,total:u,page:c,setPage:l,totalPages:f,loading:i,error:o,refresh:m,create:(0,j.useCallback)(async t=>{e&&(await T(e,t),m())},[e,m]),update:(0,j.useCallback)(async(t,n)=>{if(!e)return;let i=await E(e,t,n);return r(e=>e.map(e=>e.id===t?i:e)),i},[e]),remove:(0,j.useCallback)(async t=>{e&&(await k(e,t),m())},[e,m])}}var N=t();function P(){let{projectId:e}=i(),t=r(),[n,w]=a(),T=C(`skills`),{skills:E,page:O,setPage:k,totalPages:P,loading:F,error:I,refresh:L}=M(e??null,25),[R,z]=(0,j.useState)(n.get(`q`)||``),[B,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1);S(e??null,(0,j.useCallback)(e=>{e.type.startsWith(`skill:`)&&L()},[L]));let W=(0,j.useCallback)(async t=>{if(!e||!t.trim()){V(null);return}U(!0);try{V(await D(e,t.trim()))}catch{}finally{U(!1)}},[e]);(0,j.useEffect)(()=>{let e=n.get(`q`);e?.trim()&&W(e)},[]);let G=()=>{let e=new URLSearchParams(n);R.trim()?e.set(`q`,R.trim()):e.delete(`q`),w(e,{replace:!0}),W(R)},K=()=>{z(``),V(null);let e=new URLSearchParams(n);e.delete(`q`),w(e,{replace:!0})},q=B??E;return(0,N.jsxs)(s,{children:[(0,N.jsx)(b,{breadcrumbs:[{label:`Skills`}],actions:T?(0,N.jsx)(c,{variant:`contained`,startIcon:(0,N.jsx)(h,{}),onClick:()=>t(`new`),children:`New Skill`}):void 0}),(0,N.jsx)(v,{children:(0,N.jsx)(d,{fullWidth:!0,size:`small`,placeholder:`Semantic search skills...`,value:R,onChange:e=>z(e.target.value),onKeyDown:e=>e.key===`Enter`&&G(),slotProps:{input:{startAdornment:(0,N.jsx)(o,{position:`start`,children:(0,N.jsx)(g,{})}),endAdornment:R&&(0,N.jsx)(o,{position:`end`,children:(0,N.jsx)(f,{size:`small`,onClick:K,children:(0,N.jsx)(m,{})})})}}})}),B&&(0,N.jsxs)(s,{sx:{mb:1,color:`text.secondary`,fontSize:`0.75rem`},children:[B.length,` result`,B.length===1?``:`s`,` found`]}),!B&&(0,N.jsx)(s,{sx:{mb:2},children:(0,N.jsx)(x,{page:O,totalPages:P,onPageChange:k,onRefresh:L})}),I&&(0,N.jsx)(p,{severity:`error`,sx:{mb:2},children:I}),F||H?(0,N.jsx)(s,{sx:{display:`flex`,justifyContent:`center`,py:4},children:(0,N.jsx)(l,{})}):q.length===0?(0,N.jsx)(y,{icon:(0,N.jsx)(_,{}),title:B?`No matching skills found`:`No skills yet`,description:B?`Try a different search query`:`Create your first skill to get started`,action:!B&&T?(0,N.jsx)(c,{variant:`contained`,startIcon:(0,N.jsx)(h,{}),onClick:()=>t(`new`),children:`New Skill`}):void 0}):(0,N.jsx)(u,{spacing:2,children:q.map(e=>(0,N.jsx)(A,{skill:e,score:`score`in e?e.score:void 0,onClick:()=>t(e.id),onEdit:T?()=>t(`${e.id}/edit`):void 0},e.id))}),!B&&(0,N.jsx)(s,{sx:{mt:2},children:(0,N.jsx)(x,{page:O,totalPages:P,onPageChange:k,onRefresh:L})})]})}export{P as default};