import{r,D as $,w as j,e as P,j as G,l as N,s as _,i as D,k as H}from"./index-Daq5M5bC.js";import{s as x}from"./index-B33Yn3RC.js";var W=(e,t,a,s,u,l,d,h)=>{let m=document.documentElement,v=["light","dark"];function y(n){(Array.isArray(e)?e:[e]).forEach(f=>{let b=f==="class",k=b&&l?u.map(S=>l[S]||S):u;b?(m.classList.remove(...k),m.classList.add(l&&l[n]?l[n]:n)):m.setAttribute(f,n)}),C(n)}function C(n){h&&v.includes(n)&&(m.style.colorScheme=n)}function c(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(s)y(s);else try{let n=localStorage.getItem(t)||a,f=d&&n==="system"?c():n;y(f)}catch{}},K=["light","dark"],F="(prefers-color-scheme: dark)",z=typeof window>"u",I=r.createContext(void 0),J={setTheme:e=>{},themes:[]},te=()=>{var e;return(e=r.useContext(I))!=null?e:J},R=e=>r.useContext(I)?r.createElement(r.Fragment,null,e.children):r.createElement(Q,{...e}),U=["light","dark"],Q=({forcedTheme:e,disableTransitionOnChange:t=!1,enableSystem:a=!0,enableColorScheme:s=!0,storageKey:u="theme",themes:l=U,defaultTheme:d=a?"system":"light",attribute:h="data-theme",value:m,children:v,nonce:y,scriptProps:C})=>{let[c,n]=r.useState(()=>B(u,d)),[f,b]=r.useState(()=>c==="system"?A():c),k=m?Object.values(m):l,S=r.useCallback(o=>{let i=o;if(!i)return;o==="system"&&a&&(i=A());let w=m?m[i]:i,L=t?X(y):null,p=document.documentElement,M=g=>{g==="class"?(p.classList.remove(...k),w&&p.classList.add(w)):g.startsWith("data-")&&(w?p.setAttribute(g,w):p.removeAttribute(g))};if(Array.isArray(h)?h.forEach(M):M(h),s){let g=K.includes(d)?d:null,V=K.includes(i)?i:g;p.style.colorScheme=V}L==null||L()},[y]),T=r.useCallback(o=>{let i=typeof o=="function"?o(c):o;n(i);try{localStorage.setItem(u,i)}catch{}},[c]),E=r.useCallback(o=>{let i=A(o);b(i),c==="system"&&a&&!e&&S("system")},[c,e]);r.useEffect(()=>{let o=window.matchMedia(F);return o.addListener(E),E(o),()=>o.removeListener(E)},[E]),r.useEffect(()=>{let o=i=>{i.key===u&&(i.newValue?n(i.newValue):T(d))};return window.addEventListener("storage",o),()=>window.removeEventListener("storage",o)},[T]),r.useEffect(()=>{S(e??c)},[e,c]);let O=r.useMemo(()=>({theme:c,setTheme:T,forcedTheme:e,resolvedTheme:c==="system"?f:c,themes:a?[...l,"system"]:l,systemTheme:a?f:void 0}),[c,T,e,f,a,l]);return r.createElement(I.Provider,{value:O},r.createElement(q,{forcedTheme:e,storageKey:u,attribute:h,enableSystem:a,enableColorScheme:s,defaultTheme:d,value:m,themes:l,nonce:y,scriptProps:C}),v)},q=r.memo(({forcedTheme:e,storageKey:t,attribute:a,enableSystem:s,enableColorScheme:u,defaultTheme:l,value:d,themes:h,nonce:m,scriptProps:v})=>{let y=JSON.stringify([a,t,l,e,h,d,s,u]).slice(1,-1);return r.createElement("script",{...v,suppressHydrationWarning:!0,nonce:typeof window>"u"?m:"",dangerouslySetInnerHTML:{__html:`(${W.toString()})(${y})`}})}),B=(e,t)=>{if(z)return;let a;try{a=localStorage.getItem(e)||void 0}catch{}return a||t},X=e=>{let t=document.createElement("style");return e&&t.setAttribute("nonce",e),t.appendChild(document.createTextNode("*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(t),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(t)},1)}},A=e=>(e||(e=window.matchMedia(F)),e.matches?"dark":"light");function Y(){const[e,t]=r.useState($.theme);return r.useEffect(()=>{(async()=>{const s=await P();t(s.theme)})()},[]),r.useEffect(()=>{j(s=>{s!=null&&s.theme&&t(s.theme)})},[]),{theme:e}}r.createContext(void 0);function ae({children:e,...t}){const{theme:a}=Y();return G.jsx(R,{attribute:"class",defaultTheme:a,enableSystem:!0,disableTransitionOnChange:!0,...t,children:e})}class re{static async get(t){try{const a=`local:${t}`;return await x.getItem(a)}catch(a){return console.error("Failed to get storage data:",a),null}}static async set(t,a){try{const s=`local:${t}`;await x.setItem(s,a)}catch(s){throw console.error("Failed to set storage data:",s),s}}static async remove(t){try{const a=`local:${t}`;await x.removeItem(a)}catch(a){throw console.error("Failed to remove storage data:",a),a}}static async getSettings(){return await P()}static async saveSettings(t){await N(t)}static async saveGeneralSettings(t){await _(t)}static async saveSubtitleSettings(t){await D(t)}static async saveAIServers(t){await H(t)}static async getVocabulary(){return await this.get("vocabulary")||{}}static async saveVocabulary(t){await this.set("vocabulary",t)}}export{re as S,ae as T,te as z};
