import{jsx as u}from"react/jsx-runtime";import{cloneElement as w,isValidElement as x,useEffect as g,useMemo as A,useState as a}from"react";import{Loading as D}from"@redocly/theme/components/Loaders/Loading";import{useDeepCompareMemoize as L,fixSpec as O}from"./utils.js";import{argValueToBoolean as B}from"../../utils/index.js";import{RedoclyOpenAPIDocs as E}from"./RedoclyOpenAPIDocs.js";import{loadAndBundleDefinition as p,loadOpenapiConfig as C}from"../../utils/loadAndBundleSpec.js";async function I(e,o,t){let n;if(t?.skipBundle){if(!e)throw new Error('spec must be specified when using "skipBundleAndConvert"');n=e}else n=await p(e||o);try{O(n)}catch{}return n}function T(e,o){return e.endsWith(".md")?p({openapi:"3.0.0",info:{title:o||"",version:"1.0",description:{$ref:e}},paths:{}}):p(e)}const k=({options:e,definitionUrl:o,definition:t,activeSampleLanguage:n,children:r})=>{const[s,l]=a(),[h,f]=a(!0),[d,y]=a(null),[m,S]=a(e||{});g(()=>{async function v(){f(!0);try{const c=await C();S({...e,...c}),y(await I(t,o,e))}catch(c){l(c.message)}}v()},[t,o,e]);const i=A(()=>{if(d)return{definition:d,options:m,definitionUrl:o,activeSampleLanguage:n}},L([d,o,m]));return g(()=>{i&&f(!1)},[i]),s||!i?null:h?B(e?.hideLoading,!1)?null:u(D,{color:"--loading-spinner-color"}):x(r)?w(r,{store:i}):null};function W({definition:e,definitionUrl:o,options:t={},activeItemId:n,activeSampleLanguage:r,activeDeepLink:s,router:l}){return u(k,{definition:e,definitionUrl:o,options:t,activeItemId:n,activeSampleLanguage:r,activeDeepLink:s,children:u(E,{withCommonStyles:!0,router:l||"hash"})})}export{k as AppProvider,W as RedoclyOpenAPIDocsStandalone,T as loadAndBundleSpecOrMd,I as loadSingle};
