import{T as je,d as De}from"./useThemeProps-1bc4d723.js";import{j as T,r as l,a9 as p,b0 as Ke,a7 as ve,b1 as ue,l as fe,b2 as z}from"./index-91e9700c.js";import{u as Oe,T as Ae}from"./ThemeProvider-ef8f8c5f.js";const Y="mode",Q="color-scheme",ge="data-color-scheme";function Pe(n){const{defaultMode:s="light",defaultLightColorScheme:c="light",defaultDarkColorScheme:m="dark",modeStorageKey:b=Y,colorSchemeStorageKey:a=Q,attribute:i=ge,colorSchemeNode:r="document.documentElement",nonce:f}=n||{};return T("script",{suppressHydrationWarning:!0,nonce:typeof window>"u"?f:"",dangerouslySetInnerHTML:{__html:`(function() {
try {
  var mode = localStorage.getItem('${b}') || '${s}';
  var colorScheme = '';
  if (mode === 'system') {
    // handle system mode
    var mql = window.matchMedia('(prefers-color-scheme: dark)');
    if (mql.matches) {
      colorScheme = localStorage.getItem('${a}-dark') || '${m}';
    } else {
      colorScheme = localStorage.getItem('${a}-light') || '${c}';
    }
  }
  if (mode === 'light') {
    colorScheme = localStorage.getItem('${a}-light') || '${c}';
  }
  if (mode === 'dark') {
    colorScheme = localStorage.getItem('${a}-dark') || '${m}';
  }
  if (colorScheme) {
    ${r}.setAttribute('${i}', colorScheme);
  }
} catch(e){}})();`}},"mui-color-scheme-init")}function Se(n){if(typeof window<"u"&&n==="system")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Ce(n,s){if(n.mode==="light"||n.mode==="system"&&n.systemMode==="light")return s("light");if(n.mode==="dark"||n.mode==="system"&&n.systemMode==="dark")return s("dark")}function Ve(n){return Ce(n,s=>{if(s==="light")return n.lightColorScheme;if(s==="dark")return n.darkColorScheme})}function B(n,s){if(typeof window>"u")return;let c;try{c=localStorage.getItem(n)||void 0,c||localStorage.setItem(n,s)}catch{}return c||s}function Re(n){const{defaultMode:s="light",defaultLightColorScheme:c,defaultDarkColorScheme:m,supportedColorSchemes:b=[],modeStorageKey:a=Y,colorSchemeStorageKey:i=Q,storageWindow:r=typeof window>"u"?void 0:window}=n,f=b.join(","),[$,k]=l.useState(()=>{const t=B(a,s),e=B(`${i}-light`,c),o=B(`${i}-dark`,m);return{mode:t,systemMode:Se(t),lightColorScheme:e,darkColorScheme:o}}),x=Ve($),L=l.useCallback(t=>{k(e=>{if(t===e.mode)return e;const o=t??s;try{localStorage.setItem(a,o)}catch{}return p({},e,{mode:o,systemMode:Se(o)})})},[a,s]),E=l.useCallback(t=>{t?typeof t=="string"?t&&!f.includes(t)?console.error(`\`${t}\` does not exist in \`theme.colorSchemes\`.`):k(e=>{const o=p({},e);return Ce(e,d=>{try{localStorage.setItem(`${i}-${d}`,t)}catch{}d==="light"&&(o.lightColorScheme=t),d==="dark"&&(o.darkColorScheme=t)}),o}):k(e=>{const o=p({},e),d=t.light===null?c:t.light,M=t.dark===null?m:t.dark;if(d)if(!f.includes(d))console.error(`\`${d}\` does not exist in \`theme.colorSchemes\`.`);else{o.lightColorScheme=d;try{localStorage.setItem(`${i}-light`,d)}catch{}}if(M)if(!f.includes(M))console.error(`\`${M}\` does not exist in \`theme.colorSchemes\`.`);else{o.darkColorScheme=M;try{localStorage.setItem(`${i}-dark`,M)}catch{}}return o}):k(e=>{try{localStorage.setItem(`${i}-light`,c),localStorage.setItem(`${i}-dark`,m)}catch{}return p({},e,{lightColorScheme:c,darkColorScheme:m})})},[f,i,c,m]),D=l.useCallback(t=>{$.mode==="system"&&k(e=>{const o=t!=null&&t.matches?"dark":"light";return e.systemMode===o?e:p({},e,{systemMode:o})})},[$.mode]),K=l.useRef(D);return K.current=D,l.useEffect(()=>{const t=(...o)=>K.current(...o),e=window.matchMedia("(prefers-color-scheme: dark)");return e.addListener(t),t(e),()=>{e.removeListener(t)}},[]),l.useEffect(()=>{if(r){const t=e=>{const o=e.newValue;typeof e.key=="string"&&e.key.startsWith(i)&&(!o||f.match(o))&&(e.key.endsWith("light")&&E({light:o}),e.key.endsWith("dark")&&E({dark:o})),e.key===a&&(!o||["light","dark","system"].includes(o))&&L(o||s)};return r.addEventListener("storage",t),()=>{r.removeEventListener("storage",t)}}},[E,L,a,i,f,s,r]),p({},$,{colorScheme:x,setMode:L,setColorScheme:E})}const Ne=["colorSchemes","components","generateCssVars","cssVarPrefix"],We="*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";function Fe(n){const{themeId:s,theme:c={},attribute:m=ge,modeStorageKey:b=Y,colorSchemeStorageKey:a=Q,defaultMode:i="light",defaultColorScheme:r,disableTransitionOnChange:f=!1,resolveTheme:$,excludeVariablesFromRoot:k}=n;(!c.colorSchemes||typeof r=="string"&&!c.colorSchemes[r]||typeof r=="object"&&!c.colorSchemes[r==null?void 0:r.light]||typeof r=="object"&&!c.colorSchemes[r==null?void 0:r.dark])&&console.error(`MUI: \`${r}\` does not exist in \`theme.colorSchemes\`.`);const x=l.createContext(void 0),L=()=>{const e=l.useContext(x);if(!e)throw new Error(Ke(19));return e};function E(e){const{children:o,theme:d=c,modeStorageKey:M=b,colorSchemeStorageKey:P=a,attribute:I=m,defaultMode:v=i,defaultColorScheme:S=r,disableTransitionOnChange:J=f,storageWindow:ye=typeof window>"u"?void 0:window,documentNode:w=typeof document>"u"?void 0:document,colorSchemeNode:V=typeof document>"u"?void 0:document.documentElement,colorSchemeSelector:O=":root",disableNestedContext:pe=!1,disableStyleSheetGeneration:ke=!1}=e,R=l.useRef(!1),X=Oe(),N=l.useContext(x),W=!!N&&!pe,Z=d[s],ee=Z||d,{colorSchemes:F={},components:Me={},generateCssVars:te=()=>({vars:{},css:{}}),cssVarPrefix:G}=ee,$e=ve(ee,Ne),U=Object.keys(F),oe=typeof S=="string"?S:S.light,re=typeof S=="string"?S:S.dark,{mode:we,setMode:ne,systemMode:se,lightColorScheme:ce,darkColorScheme:le,colorScheme:be,setColorScheme:ie}=Re({supportedColorSchemes:U,defaultLightColorScheme:oe,defaultDarkColorScheme:re,modeStorageKey:M,colorSchemeStorageKey:P,defaultMode:v,storageWindow:ye});let _=we,C=be;W&&(_=N.mode,C=N.colorScheme);const Ee=(()=>_||(v==="system"?i:v))(),Ie=(()=>C||(Ee==="dark"?re:oe))(),{css:Te,vars:ae}=te(),u=p({},$e,{components:Me,colorSchemes:F,cssVarPrefix:G,vars:ae,getColorSchemeSelector:h=>`[${I}="${h}"] &`}),q={},de={};Object.entries(F).forEach(([h,y])=>{const{css:A,vars:Le}=te(h);u.vars=ue(u.vars,Le),h===Ie&&(Object.keys(y).forEach(g=>{y[g]&&typeof y[g]=="object"?u[g]=p({},u[g],y[g]):u[g]=y[g]}),u.palette&&(u.palette.colorScheme=h));const _e=(()=>typeof S=="string"?S:v==="dark"?S.dark:S.light)();if(h===_e){if(k){const g={};k(G).forEach(H=>{g[H]=A[H],delete A[H]}),q[`[${I}="${h}"]`]=g}q[`${O}, [${I}="${h}"]`]=A}else de[`${O===":root"?"":O}[${I}="${h}"]`]=A}),u.vars=ue(u.vars,ae),l.useEffect(()=>{C&&V&&V.setAttribute(I,C)},[C,I,V]),l.useEffect(()=>{let h;if(J&&R.current&&w){const y=w.createElement("style");y.appendChild(w.createTextNode(We)),w.head.appendChild(y),window.getComputedStyle(w.body),h=setTimeout(()=>{w.head.removeChild(y)},1)}return()=>{clearTimeout(h)}},[C,J,w]),l.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]);const xe=l.useMemo(()=>({allColorSchemes:U,colorScheme:C,darkColorScheme:le,lightColorScheme:ce,mode:_,setColorScheme:ie,setMode:ne,systemMode:se}),[U,C,le,ce,_,ie,ne,se]);let me=!0;(ke||W&&(X==null?void 0:X.cssVarPrefix)===G)&&(me=!1);const he=fe(l.Fragment,{children:[me&&fe(l.Fragment,{children:[T(z,{styles:{[O]:Te}}),T(z,{styles:q}),T(z,{styles:de})]}),T(Ae,{themeId:Z?s:void 0,theme:$?$(u):u,children:o})]});return W?he:T(x.Provider,{value:xe,children:he})}const D=typeof r=="string"?r:r.light,K=typeof r=="string"?r:r.dark;return{CssVarsProvider:E,useColorScheme:L,getInitColorSchemeScript:e=>Pe(p({attribute:m,colorSchemeStorageKey:a,defaultMode:i,defaultLightColorScheme:D,defaultDarkColorScheme:K,modeStorageKey:b},e))}}const j={attribute:"data-joy-color-scheme",colorSchemeStorageKey:"joy-color-scheme",defaultLightColorScheme:"light",defaultDarkColorScheme:"dark",modeStorageKey:"joy-mode"},{CssVarsProvider:He,useColorScheme:ze,getInitColorSchemeScript:Be}=Fe({themeId:je,theme:De,attribute:j.attribute,modeStorageKey:j.modeStorageKey,colorSchemeStorageKey:j.colorSchemeStorageKey,defaultColorScheme:{light:j.defaultLightColorScheme,dark:j.defaultDarkColorScheme}});export{He as C};
