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