---
export declare type Theme = 'light' | 'dark';
declare global {
    interface DocumentEventMap {
        'set-theme': CustomEvent<Theme | null>;
    }
}
export interface Props {
    defaultTheme?: Theme;
}

const { defaultTheme = 'light' } = Astro.props as Props
---

<script type="module" define:vars={{ defaultTheme }}>
  const n="theme",r=window.matchMedia("(prefers-color-scheme: dark)");function d(){return r.matches?"dark":defaultTheme}function a(e){const o=e!==void 0?e:localStorage.getItem(n);return o!=null?o:d()}function t(e){document.documentElement.setAttribute("data-theme",e),document.documentElement.style.colorScheme=e}function l(e){e.key===n&&t(a(e.newValue))}function m(){t(a())}function c(e){e.detail?(localStorage.setItem(n,e.detail),t(e.detail)):(localStorage.removeItem(n),t(a(e.detail)))}document.addEventListener("set-theme",c),window.addEventListener("storage",l),r.addEventListener("change",m),document.addEventListener("astro:after-swap",m),t(a());
</script>
