import{pathToFileURL as m}from"url";import{removeTrailingSlash as d,slash as u}from"../../shared/utils.js";import{getClientPageDataUrl as p}from"../../shared/urls.js";function D(e){const o=e?.colorMode,{modes:t=["light","dark"],hide:c,ignoreDetection:s}=o||{},a=t&&`'${t[0]}'`,i=t?.[0],l=t?.some(n=>n===i)?`'${i}'`:void 0;return c||!a?"":`
    <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(n=>`'${n}'`)}].some((mode) => mode === e) ? e : 'light';
        ${r("modeToSet")}
      } else {
        if (window.matchMedia) {
          ${f(s,l,a)}
        } else {
          ${r()}
        }
      }
    }
    </script>`}function f(e,o,t){return e?o?r(o):t?r(t):"return":h(o)}function r(e="'light'"){return`document.documentElement.className = ${e};`}function h(e="'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 {
      ${r(e)}
    }
    `}async function M(e){try{return process.env.REDOCLY_STATIC_BUNDLE?await import("@portal/server-props"):await import(m(`${u(e)}/server-props-entry.js`)+"?"+new Date)}catch{return{}}}function $(e){const o=e.split("/").map(encodeURIComponent).join("/"),t=o==="/"?o:d(o);return`<link rel="preload" as="fetch" crossorigin="anonymous" href="${p(t)}" />`}export{D as detectColorSchemaScript,$ as generatePreloadPageData,M as importServerProps};
