import{jsx as d}from"react/jsx-runtime";import{memo as v,useCallback as y,useEffect as g,useMemo as b}from"react";import S from"@markdoc/markdoc";import{LayoutVariant as M}from"@redocly/config";import{createStore as E,Provider as O}from"jotai";import{html as A}from"@redocly/theme/markdoc/tags/html";import{Heading as P}from"@redocly/theme/markdoc/components/Heading/Heading";import{normalizeOptions as N,OpenAPIParser as R}from"../../services/index.js";import{SchemaDefinition as T}from"../SchemaDefinition/index.js";import{McpTool as D,McpResource as j,McpPrompt as k}from"../McpTool/index.js";import{getMarkdownHeaderId as x}from"./utils.js";import{mergeInMockServer as C}from"../../models/operation.js";import{normalizeServers as H}from"../../utils/index.js";import{appStore as I,appStoreOverrideAtom as L,layoutAtom as l,allowedEnvironmentsAtom as V,environmentAtom as z,userClaimsAtom as _}from"../../jotai/app.js";import{mapObject as q}from"../../utils/object.js";import{getServerEnvName as B}from"../../utils/environments.js";import{globalStoreAtom as F}from"../../jotai/store.js";import{getDefaultOperationStore as W,operationStore as h}from"../../jotai/operation.js";const G={ignoreNamedSchemas:["java.io.ObjectStreamField"],maxDisplayedEnumValues:10,markdocOptions:{tags:{html:A.schema,schemaDefinition:{render:"SchemaDefinition",attributes:{schemaRef:{type:String},exampleRef:{type:String},showReadOnly:{type:Boolean},showWriteOnly:{type:Boolean},htmlWrap:{type:String,default:!1}}},mcpTool:{render:"McpTool",attributes:{name:{type:String},id:{type:String}}},mcpResource:{render:"McpResource",attributes:{name:{type:String},id:{type:String}}},mcpPrompt:{render:"McpPrompt",attributes:{name:{type:String},id:{type:String}}}},nodes:{heading:{children:["inline"],attributes:{id:{type:String},level:{type:Number,required:!0,default:1}},transform(n,m){const t=n.transformAttributes(m),i=n.transformChildren(m),e=typeof t.id=="string"?t.id:x(i);return new S.Tag("Heading",{...t,id:e,level:n.attributes.level},i)}}},components:{SchemaDefinition:T,McpTool:D,McpResource:j,McpPrompt:k,Heading:P}}},pe=v(({children:n,options:m,definitionUrl:t,definition:i,withState:e})=>{const p=y(()=>{const r=N(m,G),o=new R(i,t,r);return{options:r,parser:o}},[i,t,m]),a=b(()=>{const r=E(),o=p();r.set(F,o);const c=H(o.parser.definitionUrl,C(o.parser.definition?.servers||[],o.options.mockServer));r.sub(I,()=>{}),r.set(l,e?.layout||o.options?.layout||M.THREE_PANEL);const u=Object.fromEntries(c.map(s=>[B(s),{server:s.url,...q(s.variables||{},f=>f.default||"")}]));if(r.set(z,{environments:u}),r.set(_,e?.userClaims||{}),r.set(V,e?.allowedEnvironments),e&&r.set(L,{activeMimeName:e.activeMimeName,userClaims:e.userClaims,environment:e.environment,environments:e.environments}),e?.operation){const s=W(e.operation.pointer,e.operation.state.requestValues,e.operation.state.activeExampleName);r.set(h(e.operation.pointer),s)}return r},[p,e]);return g(()=>{e?.layout&&a.set(l,e?.layout)},[a,e?.layout]),d(O,{store:a,children:n})});export{pe as StoreProvider};
