'use client';

import { ThemeProvider } from 'next-themes';
import { useEffect } from 'react';
import { useAppEnv } from '@/lib/env-store';
import { DynamicFavicon } from '@/components/DynamicFavicon';

function SettingsLoader() {
  const loadFromApi = useAppEnv((s) => s.loadFromApi);

  useEffect(() => {
    loadFromApi();
  }, [loadFromApi]);

  return null;
}

export default function Providers({ children }: { children: React.ReactNode }) {
  return (
    <ThemeProvider attribute="class" defaultTheme="light" enableSystem>
      <SettingsLoader />
      <DynamicFavicon />
      {children}
    </ThemeProvider>
  );
}
