"use client";

import { useEffect } from "react";

import { useAuthStore } from "@/stores/auth-store";
import { STORAGE_KEYS } from "@/types/novalife";

export function DemoDataInit() {
  const loadFromStorage = useAuthStore((s) => s.loadFromStorage);

  useEffect(() => {
    if (typeof globalThis.window === "undefined") return;

    // Seed marker
    if (!localStorage.getItem(STORAGE_KEYS.DEMO_SEEDED)) {
      localStorage.setItem(STORAGE_KEYS.DEMO_SEEDED, "true");
    }

    // Rehydrate auth state from localStorage on every page load globally
    loadFromStorage();
  }, [loadFromStorage]);

  return null;
}
