// @bun
import{defaultDocRegistry as O}from"@contractspec/lib.contracts-spec/docs";import{useMemo as P}from"react";function Z(F,J){return P(()=>{try{return O.list().filter(({block:G})=>{let q=G.id.toLowerCase().includes(F.toLowerCase())||G.title.toLowerCase().includes(F.toLowerCase()),Q=J?.some((A)=>G.tags?.some((M)=>M.toLowerCase().includes(A.toLowerCase())));return q||Q}).map(({block:G,route:q})=>({id:G.id,title:G.title,summary:G.summary,route:q}))}catch(T){return console.error("Failed to fetch related docs:",T),[]}},[F,J])}import{Breadcrumbs as _,CodeBlock as $,EmptyState as N,PageHeaderResponsive as m,StatusChip as U}from"@contractspec/lib.design-system";import{Card as X}from"@contractspec/lib.ui-kit-web/ui/card";import{Box as i,HStack as W,VStack as I}from"@contractspec/lib.ui-kit-web/ui/stack";import{cn as w}from"@contractspec/lib.ui-kit-web/ui/utils";import{BookOpen as D,Code as K,Database as g,Radio as L}from"lucide-react";import B from"next/link";import{jsx as E,jsxs as z}from"react/jsx-runtime";function b({feature:F,eventKey:J,event:Y,spec:T,className:G}){let q=Y??F.events?.find((A)=>A.key===J),Q=Z(q?.key||"",T?.meta?.tags);if(!q)return z(I,{gap:"lg",className:w("mx-auto w-full max-w-5xl p-6",G),children:[E(m,{title:"Event Not Found",subtitle:`Event ${J} not found in feature ${F.meta.key}`,breadcrumb:E(_,{items:[{label:"Features",href:"/features"},{label:F.meta.title||F.meta.key,href:`/features/${F.meta.key}`},{label:"Events",href:`/features/${F.meta.key}/events`}]})}),E(N,{title:"Event not found",description:`The event '${J}' could not be found in this feature.`,icon:E(L,{className:"h-12 w-12 text-muted-foreground"})})]});return z(I,{gap:"lg",className:w("mx-auto w-full max-w-5xl p-6",G),children:[E(m,{title:q.key,subtitle:`Event defined in ${F.meta.title??F.meta.key}`,breadcrumb:E(_,{items:[{label:"Features",href:"/features"},{label:F.meta.title||F.meta.key,href:`/features/${F.meta.key}`},{label:"Events",href:`/features/${F.meta.key}#events`},{label:q.key}]})}),z(W,{gap:"sm",children:[E(U,{tone:"neutral",label:q.key,size:"sm",icon:E(L,{className:"h-3 w-3"})}),E(U,{tone:"neutral",label:`v${q.version}`,size:"sm"}),T?.meta?.stability?E(U,{tone:T.meta.stability==="stable"?"success":"warning",label:T.meta.stability,size:"sm"}):null]}),z("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3",children:[E("div",{className:"space-y-6 lg:col-span-2",children:E(X,{className:"p-6",children:z(I,{gap:"md",children:[z(W,{className:"items-center gap-2 border-b pb-2",children:[E(K,{className:"h-5 w-5 text-muted-foreground"}),E("h3",{className:"font-semibold text-lg",children:"Payload Definition"})]}),T?z(I,{gap:"lg",children:[T.meta.description&&E("p",{className:"text-muted-foreground",children:T.meta.description}),z(i,{className:"flex-col gap-2",children:[E("span",{className:"font-medium text-muted-foreground text-sm uppercase tracking-wider",children:"Payload Schema"}),E($,{code:JSON.stringify(T.payload,null,2),language:"json"})]})]}):z(I,{gap:"md",children:[E("p",{className:"text-muted-foreground",children:"Full payload details are not available for this event reference."}),E($,{code:JSON.stringify(q,null,2),language:"json"})]})]})})}),E("div",{className:"space-y-6",children:E(X,{className:"p-6",children:z(I,{gap:"md",children:[z(W,{className:"items-center gap-2 border-b pb-2",children:[E(g,{className:"h-5 w-5 text-muted-foreground"}),E("h3",{className:"font-semibold text-lg",children:"Metadata"})]}),z("dl",{className:"grid grid-cols-1 gap-4 text-sm",children:[z("div",{children:[E("dt",{className:"text-muted-foreground",children:"Key"}),E("dd",{className:"truncate font-medium",children:q.key})]}),z("div",{children:[E("dt",{className:"text-muted-foreground",children:"Version"}),E("dd",{className:"font-medium",children:q.version})]}),T?.meta?.owners&&z("div",{children:[E("dt",{className:"text-muted-foreground",children:"Owners"}),E("dd",{className:"flex flex-wrap gap-1 font-medium",children:T.meta.owners.map((A)=>E(U,{label:A,size:"sm",tone:"neutral"},A))})]})]})]})})}),Q?.length?E("div",{className:"lg:col-span-3",children:E(X,{className:"p-6",children:z(I,{gap:"md",children:[z(W,{className:"items-center gap-2 border-b pb-2",children:[E(D,{className:"h-5 w-5 text-muted-foreground"}),E("h3",{className:"font-semibold text-lg",children:"Related Documentation"})]}),E("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3",children:Q.map((A)=>E(B,{href:A.route||`/docs/${A.id}`,className:"group block",children:z("div",{className:"h-full rounded-lg border p-4 transition-colors hover:border-primary",children:[E("h4",{className:"mb-1 font-semibold group-hover:text-primary",children:A.title}),A.summary&&E("p",{className:"line-clamp-2 text-muted-foreground text-sm",children:A.summary})]})},A.id))})]})})}):null]})]})}export{b as FeatureEventDetailTemplate};
