"use client";

import { useEffect } from "react";
import { applyCafeTheme, DEFAULT_CAFE_THEME, normalizeCafeTheme } from "@/lib/cafe-theme";
import { useCafeSettings } from "@/lib/hooks/use-cafe-settings";
import { useAuthStore } from "@/lib/stores/auth.store";

export function CafeThemeProvider({ children }: { children: React.ReactNode }) {
  const cafeId = useAuthStore((s) => s.user?.cafeId);
  const { data } = useCafeSettings(cafeId);

  useEffect(() => {
    const theme = normalizeCafeTheme(data?.theme ?? DEFAULT_CAFE_THEME);
    applyCafeTheme(theme);
  }, [data?.theme]);

  return children;
}
