import { createContext, useContext, useState, type ReactNode } from 'react';

interface LanguageContextType {
  targetLanguage: string;
  toggleLanguage: (lang: string) => void;
}

const LanguageContext = createContext<LanguageContextType | undefined>(undefined);

export const useLanguage = (): LanguageContextType => {
  const context = useContext(LanguageContext);
  if (!context) {
    throw new Error('useLanguage must be used within a LanguageProvider');
  }
  return context;
};

interface LanguageProviderProps {
  children: ReactNode;
}

export const LanguageProvider = ({ children }: LanguageProviderProps) => {
  const [targetLanguage, setTargetLanguage] = useState('en');

  const toggleLanguage = (lang: string) => {
    setTargetLanguage(lang);
  };

  return (
    <LanguageContext.Provider value={{ targetLanguage, toggleLanguage }}>
      {children}
    </LanguageContext.Provider>
  );
};
