import{pathToFileURL as m}from"url";import{removeTrailingSlash as d}from"../../utils/url/remove-trailing-slash.js";import{slash as u}from"../../utils/path/slash.js";import{getClientPageDataUrl as p}from"../../utils/url/get-client-page-data-url.js";function C(o){const e=o?.colorMode,{modes:t=["light","dark"],hide:s,ignoreDetection:c}=e||{},n=t&&`'${t[0]}'`,r=t?.[0],l=t?.some(i=>i===r)?`'${r}'`:void 0;return s||!n?"":`
    <script>
    if(window&&document.documentElement)
    {
      const q=new URLSearchParams(window.location.search).get("colorSchema");
      const e=q || window.localStorage.getItem("colorSchema");
      if(e) {
        const modeToSet = [${t.map(i=>`'${i}'`)}].some((mode) => mode === e) ? e : 'light';
        ${a("modeToSet")}
      } else {
        if (window.matchMedia) {
          ${h(c,l,n)}
        } else {
          ${a()}
        }
      }
    }
    </script>`}function h(o,e,t){return o?e?a(e):t?a(t):"return":f(e)}function a(o="'light'"){return`document.documentElement.className = ${o};`}function f(o="'light'"){return`if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
      document.documentElement.className = 'dark';
    } else if(window.matchMedia('(prefers-color-scheme: light)').matches) {
      document.documentElement.className = 'light';
    } else {
      ${a(o)}
    }
    `}async function D(o){try{return process.env.REDOCLY_STATIC_BUNDLE?await import("@portal/server-props"):await import(m(`${u(o)}/server-props-entry.js`)+"?"+new Date)}catch{return{}}}function M(o){const e=o.split("/").map(encodeURIComponent).join("/"),t=e==="/"?e:d(e);return`<link rel="preload" as="fetch" crossorigin="anonymous" href="${p(t)}" />`}const E=(o,e)=>{if(!e)return{params:[],queries:{}};const t=o.slug||"",c=e.req.path.split(t.endsWith("/")?t:`${t}/`)[1]||"",n=e.req.query(),r=c.replace("data.json","");return!r||r==="/"?{params:[],queries:n}:{params:r.split("/").filter(Boolean),queries:n}};export{C as detectColorSchemaScript,M as generatePreloadPageData,E as getPathParams,D as importServerProps};
