import{pathToFileURL as d}from"url";import{removeTrailingSlash as u}from"../../utils/url/remove-trailing-slash.js";import{slash as p}from"../../utils/path/slash.js";import{getClientPageDataUrl as f}from"../../utils/url/get-client-page-data-url.js";import{DEFAULT_COLOR_MODES as m}from"@redocly/theme/core/constants";import{envConfig as h}from"../config/env-config.js";function C(t){const o=t?.colorMode,{modes:e=[m.LIGHT,m.DARK],hide:r,ignoreDetection:n}=o||{},a=e&&`'${e[0]}'`,s=e?.[0],l=e?.some(c=>c===s)?`'${s}'`:void 0;return r||!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 = [${e.map(c=>`'${c}'`)}].some((mode) => mode === e) ? e : 'light';
        ${i("modeToSet",e)}
      } else {
        if (window.matchMedia) {
          ${g(n,l,a,e)}
        } else {
          ${i(a,e)}
        }
      }
    }
    </script>`}function g(t,o,e,r=["light","dark"]){return t?o?i(o,r):e?i(e,r):"return":$(o,r)}function i(t=`'${m.LIGHT}'`,o=["light","dark"]){return`(function() {
          var root = document.documentElement;
          var modes = [${o.map(r=>`'${r}'`).join(", ")}];
          var value = ${t};
          modes.forEach(function(className) {
            root.classList.remove(className);
          });
          root.classList.add(value);
        })();`}function $(t,o=["light","dark"]){const e=o.map(n=>`'${n}'`).join(", "),r=t?`root.classList.add(${t});`:"";return`(function() {
          var root = document.documentElement;
          var modes = [${e}];
          modes.forEach(function(className) {
            root.classList.remove(className);
          });
          if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
            root.classList.add('dark');
          } else if (window.matchMedia('(prefers-color-scheme: light)').matches) {
            root.classList.add('light');
          }${r?` else {
            ${r}
          }`:""}
        })();`}async function E(t){try{return h.isRuntimeMode?await import("@portal/server-props"):await import(d(`${p(t)}/server-props-entry.js`)+"?"+new Date)}catch{return{}}}function T(t){const o=t.split("/").map(encodeURIComponent).join("/"),e=o==="/"?o:u(o);return`<link rel="preload" as="fetch" crossorigin="anonymous" href="${f(e)}" />`}const k=(t,o)=>{if(!o)return{params:[],queries:{}};const e=t.slug||"",n=o.req.path.split(e.endsWith("/")?e:`${e}/`)[1]||"",a=o.req.query(),s=n.replace("data.json","");return!s||s==="/"?{params:[],queries:a}:{params:s.split("/").filter(Boolean),queries:a}};export{C as detectColorSchemaScript,T as generatePreloadPageData,k as getPathParams,E as importServerProps};
