import React, { useState, useEffect } from 'react';
import { ThemeContext } from "./ThemeContext";

export function ThemeProvider({ children }: { children: React.ReactNode }) {
  const [dark, setDark] = useState(false);

  useEffect(() => {
    const root = document.documentElement;
    if (dark) {
      root.classList.add('plimi-theme-dark');
      root.classList.remove('plimi-theme-light');
    } else {
      root.classList.add('plimi-theme-light');
      root.classList.remove('plimi-theme-dark');
    }
  }, [dark]);

  const toggleTheme = () => setDark(!dark);

  return (
    <ThemeContext.Provider value={{ dark, toggleTheme }}>
      {children}
    </ThemeContext.Provider>
  );
}
