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