import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{c as ee,l as te,u as r}from"./vendor-react-Cts2Wj-s.js";import{N as i,O as a,Q as o,T as s,at as c,g as ne,i as re,it as l,k as u,nt as d,pt as f,rt as ie,ut as ae,w as p}from"./vendor-mui-Ckcy4Lfd.js";import"./vendor-md-editor-DC6xr_29.js";import{$ as m,B as h,L as g,ft as oe,mt as _,nt as v}from"./vendor-mui-icons-606Bohdn.js";import{_ as y,f as b,i as x,p as S,u as C}from"./ui-BLXHSX1T.js";import{t as w}from"./usePagination-DY41LU0X.js";import{i as T,n as E,r as D}from"./api-DqPuu8Cs.js";var O=e(n(),1),k=t();function A(){let{projectId:e}=te(),t=ee(),[n,A]=r(),{palette:j}=f(),[M,se]=(0,O.useState)([]),[ce,N]=(0,O.useState)(!0),[P,F]=(0,O.useState)(null),{page:I,setPage:L,total:R,setTotal:z,totalPages:B,offset:V,pageSize:H}=w(25),[U,W]=(0,O.useState)(null),[le,G]=(0,O.useState)([]),[ue,K]=(0,O.useState)(!1),[q,J]=(0,O.useState)(n.get(`q`)||``),[Y,X]=(0,O.useState)(null),[de,Z]=(0,O.useState)(!1),Q=(0,O.useCallback)(async()=>{if(e){N(!0);try{let{items:t,total:n}=await D(e,{limit:H,offset:V});se(t),z(n),F(null)}catch(e){F(e instanceof Error?e.message:String(e))}finally{N(!1)}}},[e,H,V,z]);(0,O.useEffect)(()=>{Q()},[Q]);let fe=async t=>{if(U===t){W(null);return}W(t),K(!0);try{G(await E(e,t))}catch{G([])}finally{K(!1)}},$=(0,O.useCallback)(async t=>{if(!e||!t.trim()){X(null);return}Z(!0);try{X(await T(e,t.trim(),{topK:20,minScore:.1}))}catch{}finally{Z(!1)}},[e]);(0,O.useEffect)(()=>{let e=n.get(`q`);e?.trim()&&$(e)},[]);let pe=()=>{let e=new URLSearchParams(n);q.trim()?e.set(`q`,q.trim()):e.delete(`q`),A(e,{replace:!0}),$(q)};return(0,k.jsxs)(o,{children:[(0,k.jsx)(S,{breadcrumbs:[{label:`Docs`}],actions:(0,k.jsxs)(d,{variant:`body2`,sx:{color:j.custom.textMuted},children:[R,` files`]})}),(0,k.jsx)(b,{children:(0,k.jsx)(re,{fullWidth:!0,size:`small`,placeholder:`Semantic search docs...`,value:q,onChange:e=>J(e.target.value),onKeyDown:e=>e.key===`Enter`&&pe(),slotProps:{input:{startAdornment:(0,k.jsx)(i,{position:`start`,children:(0,k.jsx)(oe,{})}),endAdornment:q&&(0,k.jsx)(i,{position:`end`,children:(0,k.jsx)(l,{size:`small`,onClick:()=>{J(``),X(null);let e=new URLSearchParams(n);e.delete(`q`),A(e,{replace:!0})},children:(0,k.jsx)(m,{})})})}}})}),Y&&(0,k.jsxs)(d,{variant:`caption`,sx:{color:j.custom.textMuted,mb:1,display:`block`},children:[Y.length,` result`,Y.length===1?``:`s`,` found`]}),!Y&&(0,k.jsx)(o,{sx:{mb:2},children:(0,k.jsx)(C,{page:I,totalPages:B,onPageChange:L,onRefresh:Q})}),P&&(0,k.jsx)(ie,{severity:`error`,sx:{mb:2},children:P}),ce||de?(0,k.jsx)(o,{sx:{display:`flex`,justifyContent:`center`,py:4},children:(0,k.jsx)(c,{})}):Y?(0,k.jsx)(u,{disablePadding:!0,children:Y.map(e=>(0,k.jsxs)(a,{onClick:()=>t(encodeURIComponent(e.id)),sx:{borderRadius:1,mb:.5},children:[(0,k.jsx)(s,{sx:{minWidth:36},children:(0,k.jsx)(g,{fontSize:`small`,color:`secondary`})}),(0,k.jsx)(p,{primary:(0,k.jsxs)(o,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,k.jsx)(d,{variant:`body2`,fontWeight:600,children:e.title||e.id}),(0,k.jsx)(y,{label:`${(e.score*100).toFixed(0)}%`,color:`primary`,size:`small`})]}),secondary:(0,k.jsxs)(d,{variant:`caption`,sx:{color:j.custom.textMuted},noWrap:!0,children:[e.fileId,` · level `,e.level,e.content?` · ${e.content.slice(0,100)}`:``]})})]},e.id))}):M.length===0?(0,k.jsx)(x,{icon:(0,k.jsx)(_,{}),title:`No docs indexed`,description:`Configure docsPattern in graph-memory.yaml to start indexing documentation`}):(0,k.jsx)(u,{disablePadding:!0,children:M.map(e=>(0,k.jsxs)(o,{children:[(0,k.jsxs)(a,{onClick:()=>fe(e.fileId),sx:{borderRadius:1},children:[(0,k.jsx)(s,{sx:{minWidth:36},children:U===e.fileId?(0,k.jsx)(v,{}):(0,k.jsx)(h,{})}),(0,k.jsx)(s,{sx:{minWidth:36},children:(0,k.jsx)(_,{fontSize:`small`,color:`secondary`})}),(0,k.jsx)(p,{primary:(0,k.jsx)(d,{variant:`body2`,fontWeight:600,children:e.title||e.fileId}),secondary:(0,k.jsxs)(d,{variant:`caption`,sx:{color:j.custom.textMuted},children:[e.fileId,` · `,e.chunks,` chunks`]})})]}),(0,k.jsx)(ae,{in:U===e.fileId,timeout:`auto`,unmountOnExit:!0,children:ue?(0,k.jsx)(o,{sx:{pl:9,py:1},children:(0,k.jsx)(c,{size:16})}):(0,k.jsx)(u,{disablePadding:!0,sx:{pl:4},children:le.map(e=>(0,k.jsxs)(a,{onClick:()=>t(encodeURIComponent(e.id)),sx:{borderRadius:1,py:.5},children:[(0,k.jsx)(s,{sx:{minWidth:36},children:(0,k.jsx)(g,{fontSize:`small`,sx:{opacity:.5}})}),(0,k.jsx)(p,{primary:(0,k.jsxs)(ne,{direction:`row`,spacing:1,alignItems:`center`,children:[(0,k.jsx)(d,{variant:`body2`,sx:{pl:(e.level-1)*2},children:e.title||e.id}),e.language&&(0,k.jsx)(y,{label:e.language,color:`primary`,size:`small`})]}),secondary:e.content?(0,k.jsx)(d,{variant:`caption`,sx:{color:j.custom.textMuted,pl:(e.level-1)*2},noWrap:!0,children:e.content.slice(0,120)}):void 0})]},e.id))})})]},e.fileId))}),!Y&&(0,k.jsx)(o,{sx:{mt:2},children:(0,k.jsx)(C,{page:I,totalPages:B,onPageChange:L,onRefresh:Q})})]})}export{A as default};