import fiTranslations from '../locales/fi.json';
import enTranslations from '../locales/en.json';
import svTranslations from '../locales/sv.json';

const translations = {
    fi: fiTranslations,
    en: enTranslations,
    sv: svTranslations,
};

export type Locale = 'fi' | 'en' | 'sv';

// For App Router - we'll get locale from URL params or default to 'fi'
export function useTranslations(locale: Locale = 'fi') {
    const t = (key: string): string => {
        const keys = key.split('.');
        let value: unknown = translations[locale];

        for (const k of keys) {
            value = (value as Record<string, unknown>)?.[k];
        }

        return (value as string) || key;
    };

    return { t, locale };
}

export function getTranslations(locale: Locale = 'fi') {
    const t = (key: string): string => {
        const keys = key.split('.');
        let value: unknown = translations[locale];

        for (const k of keys) {
            value = (value as Record<string, unknown>)?.[k];
        }

        return (value as string) || key;
    };

    return { t, locale };
}
