'use client';

import { createContext, useContext } from 'react';
import { Theme, isValidTheme } from '../themes';

interface ThemeContextValue {
  theme: Theme;
}

const ThemeContext = createContext<ThemeContextValue>({ theme: 'classic' });

export function ThemeProvider({ 
  theme, 
  children 
}: { 
  theme: Theme; 
  children: React.ReactNode;
}) {
  // Validate theme at runtime
  if (!isValidTheme(theme)) {
    console.warn(`Invalid theme "${theme}", falling back to "classic"`);
    theme = 'classic';
  }
  
  return (
    <ThemeContext.Provider value={{ theme }}>
      {children}
    </ThemeContext.Provider>
  );
}

export function useTheme() {
  return useContext(ThemeContext);
}
