import{useMemo as u}from"react";import{components as l}from"@redocly-markdoc/components";import{Ast as f}from"@markdoc/markdoc";import{PageNavigation as g}from"@redocly/theme/components/PageNavigation/PageNavigation";import{tags as d,components as h}from"@redocly/theme/markdoc/default";import{Breadcrumbs as _}from"@redocly/theme/components/Breadcrumbs/Breadcrumbs";import{withPathPrefix as m}from"@redocly/theme/core/utils";import{OPENAPI_DOCS_TEMPLATE_ID as y,ServerRoutes as w}from"../../../../constants/common.js";import{isBrowser as P}from"../../../../utils/env/is-browser.js";import*as S from"../../markdown/markdoc/custom-components/index.js";import*as v from"../../markdown/markdoc/nodes/index.js";import O from"../../markdown/markdoc/tags/index.js";import{usePageData as C,useSidebarSiblingsData as A}from"../../../../client/providers/page-data/hooks";import{telemetry as E}from"../../../../client/app/telemetry/index.js";import{getMockServerDocsConfig as T}from"./mock-server-config";function V(t="",r="",o="/"){return t.endsWith(o)&&(t=t.slice(0,-o.length)),r.startsWith(o)&&(r=r.slice(o.length)),!t||!r?t+r:t+o+r}function b(t){if(t)return Object.entries(t).reduce((r,[o,e])=>(r[o]=f.fromJSON(JSON.stringify(e)),r),{})}function Y(t,{markdown:r,baseSlug:o}){return u(()=>{const n=P();t.options.oAuth2RedirectURI=n?`${window.location.origin}${m(w.REPLAY_OAUTH2_CALLBACK)}`:null,t.options.routingBasePath=m(o),t.options.mockServer=T(t.options.mockServer,o),t.options.scrollYOffset=n?parseInt(getComputedStyle(document.documentElement).getPropertyValue("--navbar-height"),10):0,t.options.markdocOptions={tags:{...O,...d},nodes:{...v},components:{...S,...h,...l,...globalThis.__LOADER.markdocComponents},...r,partials:b(r?.partials)},t.options.unstable_hooks={...t.options.unstable_hooks,MiddlePanelFooter:()=>{const{templateId:i}=C()||{},{nextPage:s,prevPage:a}=A()||{};return i===y?null:g({nextPage:s,prevPage:a})},MiddlePanelHeader:()=>_({})};const p={codeSamplesLanguageSwitch:"samples_language_switch",codeSamplesCopy:"code_samples_copy",panelToggle:"panel_toggle",targetServerSwitch:"target_server_switch",tryItOpen:"try_it_toggle",tryItSent:"try_it_sent"},c={};for(const[i,s]of Object.entries(p)){const a=F(t.options.events?.[i]);c[i]=I(a,s)}return t.options.events=c,t},[t,r,o])}function F(t){if(typeof window>"u")return null;if(typeof t=="function")return t;if(typeof t!="string")return null;try{const r=t.trim();if(!r.match(/^(\([^)]*\)\s*=>\s*.+|[a-zA-Z_$][\w$]*\s*=>\s*.+)$/))throw new Error("Invalid function format. Only arrow functions allowed.");if(["eval","Function","constructor","prototype","__proto__","import","require","process","global","window","document"].some(n=>r.includes(n)))throw new Error("Function contains prohibited keywords");return new Function("event",`
      'use strict';
      const userFn = ${r};
      return userFn(event);
    `)}catch(r){return console.error("Function parsing error:",r),null}}function I(t,r){return o=>{if(t)try{t(o)}catch(e){console.error("User event handler error:",e)}if(r)try{E.sendOpenapiDocsMessage({eventType:r,operationHttpVerb:o.operationHttpVerb,operationPath:o.operationPath,lang:"lang"in o?o.lang:void 0,action:o.action,state:"state"in o?o.state:void 0,serverUrl:"serverUrl"in o?o.serverUrl:void 0})}catch{}}}export{V as joinWithSeparator,I as mergeEvents,b as parsePartials,F as safeParseFunction,Y as usePatchedStore};
