import { tr } from './locales/tr';
import { en } from './locales/en';
import { Locale, defaultLocale } from './config';

const translations = {
  tr,
  en,
} as const;

export function getTranslations(locale: Locale = defaultLocale) {
  return translations[locale] || translations[defaultLocale];
}

export function t(locale: Locale, key: string): string {
  const keys = key.split('.');
  let value: unknown = translations[locale] || translations[defaultLocale];
  
  for (const k of keys) {
    if (value && typeof value === 'object' && k in value) {
      value = (value as Record<string, unknown>)[k];
    } else {
      return key; // Return key if translation not found
    }
  }
  
  return typeof value === 'string' ? value : key;
}

export * from './config';
export * from './locales/tr';
export * from './locales/en';
