import { useTranslation as useI18nTranslation } from 'react-i18next';
import { useUIStore } from '@/stores/ui';
import type { UseTranslationReturn } from './types';

/**
 * Hook pour gérer les traductions
 * FE-TYPE-012: Fully typed hook return
 */
export function useTranslation(): UseTranslationReturn {
  const { i18n, t } = useI18nTranslation();
  const { language, setLanguage } = useUIStore();

  const changeLanguage = (newLanguage: 'en' | 'fr') => {
    void i18n.changeLanguage(newLanguage);
    setLanguage(newLanguage);
  };

  return {
    t,
    i18n: {
      ...i18n,
      changeLanguage: async (lng: string) => {
        await i18n.changeLanguage(lng);
      },
      isInitialized: i18n.isInitialized,
    },
    language,
    changeLanguage,
    isReady: i18n.isInitialized,
  };
}
