'use client';

import { ThemeProvider as NextThemesProvider, useTheme as useNextTheme } from 'next-themes';

export function ThemeProvider({ children }: { children: React.ReactNode }) {
  return (
    <NextThemesProvider
      attribute="class"
      defaultTheme="dark"
      storageKey="goodgo-theme"
      enableSystem={false}
    >
      {children}
    </NextThemesProvider>
  );
}

/**
 * Backward-compatible useTheme hook.
 * Returns `theme` ('light' | 'dark') and `toggleTheme`.
 */
export function useTheme() {
  const { theme, setTheme, resolvedTheme } = useNextTheme();
  const current = (resolvedTheme ?? theme ?? 'dark') as 'light' | 'dark';

  const toggleTheme = () => {
    setTheme(current === 'dark' ? 'light' : 'dark');
  };

  return { theme: current, toggleTheme };
}
