import{DocsIndexDataView as _,DocsSearchForm as $}from"@contractspec/lib.contracts-spec/docs";import{DataViewList as g,formRenderer as I,StatusChip as P}from"@contractspec/lib.design-system";import{HStack as L,VStack as T}from"@contractspec/lib.ui-kit-web/ui/stack";import{H1 as Q,Muted as W}from"@contractspec/lib.ui-kit-web/ui/typography";import{useMemo as X,useState as R}from"react";import{jsx as J,jsxs as U}from"react/jsx-runtime";function H(A){if(!A)return;return A.replace(/<!--.*?-->/g,"").replace(/[ \t]+/g," ").replace(/\n{3,}/g,`

`).trim()}function v(A){let B=H(A.summary),N=A.kind??(A.source==="generated"?"reference":void 0),O=A.visibility??(A.source==="generated"?"public":void 0);return{...A,summary:B,kind:N,visibility:O}}function w(A,B){if(!B)return!0;return[A.title,A.summary,A.id,...A.tags??[]].filter(Boolean).join(" ").toLowerCase().includes(B.toLowerCase())}function M({entries:A}){let[B,N]=R({}),O=X(()=>A.map(v),[A]),Y=X(()=>{let G=B.query?.trim()??"";return O.filter((K)=>{if(B.kind&&K.kind!==B.kind)return!1;if(B.visibility&&K.visibility!==B.visibility)return!1;return w(K,G)})},[B,O]),Z=I.render($,{defaultValues:{query:B.query??"",visibility:B.visibility??"",kind:B.kind??""},overrides:{onSubmitOverride:(G)=>{let K=G;N({query:K.query??"",visibility:K.visibility??"",kind:K.kind??""})}}});return U(T,{gap:"xl",children:[U(T,{gap:"sm",children:[J(Q,{children:"Reference"}),J(W,{children:"Generated reference material for public contract surfaces, versions, owners, and example-backed implementations. Use this when you need the repo truth, not just the narrative docs layer."})]}),J(T,{gap:"sm",className:"max-w-2xl",children:Z}),J(g,{spec:_,items:Y,emptyState:J(W,{children:"No reference docs match your filters."}),onSelect:(G)=>{if(G.route)window.location.assign(G.route)},renderActions:(G)=>{return U(L,{gap:"xs",justify:"end",children:[G.kind?J(P,{size:"sm",label:G.kind}):null,G.visibility?J(P,{size:"sm",label:G.visibility}):null,G.version?J(P,{size:"sm",label:`v${G.version}`}):null]})}})]})}export{M as DocsReferenceIndexClient};
