import{a as e}from"./url-D6jvVYIA.js";function t(e,t){let n;try{n=e()}catch{return}return{getItem:e=>{let r=e=>e===null?null:JSON.parse(e,t?.reviver),i=n.getItem(e)??null;return i instanceof Promise?i.then(r):r(i)},setItem:(e,r)=>n.setItem(e,JSON.stringify(r,t?.replacer)),removeItem:e=>n.removeItem(e)}}var n=e=>t=>{try{let r=e(t);return r instanceof Promise?r:{then(e){return n(e)(r)},catch(e){return this}}}catch(e){return{then(e){return this},catch(t){return n(t)(e)}}}},r=(e,r)=>(i,a,o)=>{let s={storage:t(()=>window.localStorage),partialize:e=>e,version:0,merge:(e,t)=>({...t,...e}),...r},c=!1,l=0,u=new Set,d=new Set,f=s.storage;if(!f)return e((...e)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),i(...e)},a,o);let p=()=>{let e=s.partialize({...a()});return f.setItem(s.name,{state:e,version:s.version})},m=o.setState;o.setState=(e,t)=>(m(e,t),p());let h=e((...e)=>(i(...e),p()),a,o);o.getInitialState=()=>h;let g,_=()=>{if(!f)return;let e=++l;c=!1,u.forEach(e=>e(a()??h));let t=s.onRehydrateStorage?.call(s,a()??h)||void 0;return n(f.getItem.bind(f))(s.name).then(e=>{if(e)if(typeof e.version==`number`&&e.version!==s.version){if(s.migrate){let t=s.migrate(e.state,e.version);return t instanceof Promise?t.then(e=>[!0,e]):[!0,t]}console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`)}else return[!1,e.state];return[!1,void 0]}).then(t=>{if(e!==l)return;let[n,r]=t;if(g=s.merge(r,a()??h),i(g,!0),n)return p()}).then(()=>{e===l&&(t?.(a(),void 0),g=a(),c=!0,d.forEach(e=>e(g)))}).catch(n=>{e===l&&t?.(void 0,n)})};return o.persist={setOptions:e=>{s={...s,...e},e.storage&&(f=e.storage)},clearStorage:()=>{f?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>_(),hasHydrated:()=>c,onHydrate:e=>(u.add(e),()=>{u.delete(e)}),onFinishHydration:e=>(d.add(e),()=>{d.delete(e)})},s.skipHydration||_(),g||h},i=`default`,a={light:{default:`#f5f5f7`,emerald:`#f0fdf4`,mono:`#ffffff`,clay:`#fffaf0`},dark:{default:`#1c1c1e`,emerald:`#000000`,mono:`#101010`,clay:`#0a1a1a`}};function o(e,t){let n=document.head;if(!n)return;let r=n.querySelector(`meta[name="theme-color"][data-xopc-theme-color="true"]`);r||(r=document.createElement(`meta`),r.setAttribute(`name`,`theme-color`),r.setAttribute(`data-xopc-theme-color`,`true`),n.appendChild(r)),r.setAttribute(`content`,a[e][t])}function s(){return globalThis.matchMedia?.(`(prefers-color-scheme: dark)`).matches??!1}function c(e){return e===`system`?s()?`dark`:`light`:e}function l(){return globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1}function u(e){return e===`cal`?`mono`:e===`default`||e===`emerald`||e===`mono`||e===`clay`?e:i}function d(e,t,n){let r=document.documentElement,i=()=>{r.classList.toggle(`dark`,e===`dark`),r.dataset.theme=e,r.dataset.colorScheme=t,o(e,t)},a=document;n&&!l()&&typeof a.startViewTransition==`function`?a.startViewTransition(i):i()}function f(){try{let e=localStorage.getItem(`xopc-web-theme`),t=`system`,n=i;if(e){let r=JSON.parse(e);r.state?.preference&&(t=r.state.preference),r.state&&`colorScheme`in r.state&&(n=u(r.state.colorScheme))}d(c(t),n,!1)}catch{d(c(`system`),`default`,!1)}}var p=e(r((e,t)=>({preference:`system`,colorScheme:i,resolved:c(`system`),setPreference:n=>{let r=c(n),{resolved:i,colorScheme:a}=t();d(r,a,r!==i),e({preference:n,resolved:r})},setColorScheme:n=>{let{resolved:r}=t();d(r,n,!0),e({colorScheme:n})}}),{name:`xopc-web-theme`,merge:(e,t)=>{let n=e??{};return{...t,...n,colorScheme:u(n.colorScheme)}}}));function m(){let{preference:e,colorScheme:t}=p.getState(),n=c(e);d(n,t,!1),p.setState({resolved:n})}function h(){let e=globalThis.matchMedia?.(`(prefers-color-scheme: dark)`);if(!e)return()=>{};let t=()=>{let{preference:e,colorScheme:t}=p.getState();if(e!==`system`)return;let n=c(`system`),r=p.getState().resolved;d(n,t,n!==r),p.setState({resolved:n})};return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)}export{r as a,p as i,h as n,m as r,f as t};