"use client";

import { useSyncExternalStore } from "react";

import { buildThemeBootInlineScript } from "@/scripts/theme-boot";

const emptySubscribe = () => () => {};

/**
 * Emits the theme-boot inline script only during SSR and the matching hydration
 * pass. Post-hydration client renders return null so React 19 does not warn
 * about creating a <script> during client render.
 */
export function ThemeBootScript() {
  const shouldRender = useSyncExternalStore(emptySubscribe, () => false, () => true);

  if (!shouldRender) return null;

  return (
    <script
      id="theme-boot"
      dangerouslySetInnerHTML={{ __html: buildThemeBootInlineScript() }}
    />
  );
}
