<script lang="ts">
  import { page } from '$app/state';
  import { onDestroy, onMount, type Snippet } from 'svelte';

  const {
    children,
  }: {
    children: Snippet;
  } = $props();

  onMount(() => {
    const theme =
      page.url.searchParams.get('theme') ??
      localStorage.getItem('mem.estrogen.zone:blog:theme');
    if (theme) {
      localStorage.setItem('mem.estrogen.zone:blog:theme', theme);
      document.documentElement.setAttribute('data-blog-theme', theme);
      page.url.searchParams.delete('theme');
    }
  });
  onDestroy(() => {
    if (typeof document !== 'undefined')
      document.documentElement.removeAttribute('data-blog-theme');
  });
</script>

{@render children()}
