// @bun
import{EventRegistry as Z,OperationSpecRegistry as _}from"@contractspec/lib.contracts-spec";import{DataViewRegistry as $}from"@contractspec/lib.contracts-spec/data-views";import{ContractReferenceDataView as z,ContractReferenceQuery as C,DocsGenerateCommand as E,DocsGeneratedEvent as R,DocsIndexDataView as P,DocsIndexQuery as I,DocsLayoutPresentation as q,DocsPublishCommand as T,DocsPublishedEvent as h,DocsReferencePagePresentation as m,DocsSearchForm as S,ExampleCatalogDataView as u}from"@contractspec/lib.contracts-spec/docs";import{FormRegistry as l}from"@contractspec/lib.contracts-spec/forms";import{PresentationRegistry as k}from"@contractspec/lib.contracts-spec/presentations";import{serializeDataViewSpec as v,serializeEventSpec as d,serializeFormSpec as n,serializeOperationSpec as y,serializePresentationSpec as t}from"@contractspec/lib.contracts-spec/serialization";var B=null;function o(){let b=new _;return b.register(I).register(C).register(E).register(T),b}function p(){if(!B)B=o();return B}function K(b,f){return p().get(b,f)}var D=null;function g(){let b=new Z;return b.register(R).register(h),b}function i(){if(!D)D=g();return D}function L(b,f){return i().get(b,f)}var F=null;function c(){let b=new k;return b.register(q).register(m),b}function a(){if(!F)F=c();return F}function M(b,f){return a().get(b,f)}var G=null;function r(){let b=new $;return b.register(P).register(z).register(u),b}function s(){if(!G)G=r();return G}function N(b,f){return s().get(b,f)}var H=null;function e(){let b=new l;return b.register(S),b}function bb(){if(!H)H=e();return H}function O(b,f){return bb().get(b)}function Q(b,f){let j=K(b,f);return y(j)??void 0}function U(b,f){let j=L(b,f);return d(j)??void 0}function V(b,f){let j=M(b,f);return t(j)??void 0}function W(b,f){let j=N(b,f);return v(j)??void 0}function X(b,f){let j=O(b,f);return n(j)??void 0}function fb(){B=null}function jb(){D=null}function wb(){F=null}function xb(){G=null}function Ab(){H=null}function Nb(){fb(),jb(),wb(),xb(),Ab()}import{defaultDocRegistry as Bb}from"@contractspec/lib.contracts-spec/docs";function Db(b){return b?.trim().toLowerCase()??""}function Fb(b){for(let f of b??[]){let j=Bb.get(f);if(j)return j.route}return}function Y(b,f,j,x){let A=b.meta.title??b.meta.key,w=Fb(b.meta.docId),J=b.meta.description;return{key:b.meta.key,version:b.meta.version,type:f,title:A,description:J,markdown:[`# ${A}`,`- Key: ${b.meta.key}`,`- Type: ${f}`,`- Version: ${b.meta.version}`,w?`- Docs route: ${w}`:"",J?`
${J}`:""].filter(Boolean).join(`
`),...w?{route:w}:{},...j?{schema:j}:{},...x?{policy:x}:{},tags:b.meta.tags??[],owners:b.meta.owners??[],stability:b.meta.stability}}function Vb(b){let f=b.includeSchema??!1,j=Db(b.type),x=K(b.key,b.version);if(x&&(!j||j==="operation"||j===x.meta.kind))return{reference:Y(x,x.meta.kind,f?Q(b.key,b.version):void 0,x.policy)};let A=[{type:"data-view",spec:N(b.key,b.version),schema:f?W(b.key,b.version):void 0},{type:"form",spec:O(b.key,b.version),schema:f?X(b.key,b.version):void 0},{type:"presentation",spec:M(b.key,b.version),schema:f?V(b.key,b.version):void 0},{type:"event",spec:L(b.key,b.version),schema:f?U(b.key,b.version):void 0}];for(let w of A)if(w.spec&&(!j||j===w.type))return{reference:Y(w.spec,w.type,w.schema)};throw Error(`Contract reference not found: ${b.key}`)}export{Vb as resolveContractReference};
