/* =============================================================
 * i18n - Simple translation system with localStorage persistence
 * ============================================================= */

// Translation dictionary
const translations = {
  en: {
    // Utility bar & Nav
    'restore.cta': 'Restore a father today',
    'nav.about': 'About',
    'nav.programs': 'Programs',
    'nav.forge': 'The Forge',
    'nav.stories': 'Stories',
    'nav.events': 'Events',
    'nav.getInvolved': 'Get Involved',
    'nav.contact': 'Contact',
    'nav.donate': 'Donate',
    
    // Programs menu
    'programs.beAMan': 'Be a Man',
    'programs.beAMan.desc': '12-week foundations',
    'programs.nurturingBonds': 'Nurturing Bonds',
    'programs.nurturingBonds.desc': 'Father-child rhythms',
    'programs.mobileKanaabe': 'Mobile Kanaabe',
    'programs.mobileKanaabe.desc': 'Village outreach',
    
    // Homepage Hero
    'home.hero.badge': 'An Initiative of The Remnant Generation',
    'home.hero.title1': 'Every Father Matters.',
    'home.hero.title2': 'Every Family Wins.',
    'home.hero.cta1': 'See Our Programs',
    'home.hero.cta2': 'Join the Movement',
    
    // Impact Bar
    'home.impact.fathers': 'Fathers Restored',
    'home.impact.families': 'Families Strengthened',
    'home.impact.groups': 'Active Forge Groups',
    
    // Problem Section
    'home.problem.stat1': '64% of Ugandan households lack an active father',
    'home.problem.stat2': '7 in 10 children grow up without consistent male guidance',
    'home.problem.stat3': 'Father absence linked to 3× higher poverty rates',
    'home.problem.quote': 'We don\'t restore fathers one at a time. We build brotherhood—Forge groups where men sharpen men.',
    
    // Programs Section
    'home.programs.title': 'How We Work',
    'home.programs.lede': 'Three pathways. One mission: Every father equipped, every family whole.',
    
    // Footer
    'footer.mission': 'Restoring fathers, rebuilding families across Uganda.',
    'footer.quickLinks': 'Quick Links',
    'footer.programs': 'Programs',
    'footer.connect': 'Connect',
    'footer.legal': 'Legal',
    'footer.privacy': 'Privacy Policy',
    'footer.terms': 'Terms of Use',
    'footer.rights': 'All rights reserved.',
    
    // Buttons & CTAs
    'cta.learnMore': 'Learn More',
    'cta.joinUs': 'Join Us',
    'cta.seePrograms': 'See Programs',
    'cta.donate': 'Donate Now',
    'cta.getInvolved': 'Get Involved',
    'cta.readMore': 'Read More',
    'cta.viewAll': 'View All',
  },
  lg: {
    'restore.cta': 'Zzaawo taata leero',
    'nav.about': 'Ebikwata ku ffe',
    'nav.programs': 'Pulogulaamu',
    'nav.forge': 'Forge',
    'nav.stories': 'Emboozi',
    'nav.events': 'Ebikolwa',
    'nav.getInvolved': 'Weegatte',
    'nav.contact': 'Tutukirire',
    'nav.donate': 'Waayo',
    
    'programs.beAMan': 'Beera Musajja',
    'programs.beAMan.desc': 'Wiiki 12 ez\'emisingi',
    'programs.nurturingBonds': 'Okukuza Enkolagana',
    'programs.nurturingBonds.desc': 'Taata n\'abaana',
    'programs.mobileKanaabe': 'Mobile Kanaabe',
    'programs.mobileKanaabe.desc': 'Okutuuka mu byalo',
    
    'home.hero.badge': 'Pulojekiti ya The Remnant Generation',
    'home.hero.title1': 'Buli Taata Wa Mugaso.',
    'home.hero.title2': 'Buli Famire Ewangula.',
    'home.hero.cta1': 'Laba Pulogulaamu Zaffe',
    'home.hero.cta2': 'Weegatte ku Mukutu',
    
    'home.impact.fathers': 'Abataata Abazziddwa',
    'home.impact.families': 'Amaka Aganywezeddwa',
    'home.impact.groups': 'Ebibiina bya Forge Ebikola',
    
    'home.problem.stat1': '64% w\'amaka mu Uganda tegalina taata atuufu',
    'home.problem.stat2': '7 mu 10 abaana bakula awatali buyambi bwa basajja',
    'home.problem.stat3': 'Obutaba wa taata kukwatagana n\'obwavu 3× okusingira ddala',
    'home.problem.quote': 'Tetuzzaawo bataata omu omu. Tuzimba obulamu obw\'abooluganda—ebibiina bya Forge abasajja mwe banoonyeza abasajja.',
    
    'home.programs.title': 'Engeri Gye Tukola',
    'home.programs.lede': 'Engeri ssatu. Ekigendererwa kimu: Buli taata ng\'ategekeddwa, buli famire ng\'ejjudde.',
    
    'footer.mission': 'Okuzzaawo bataata, okuzimba amaka mu Uganda yonna.',
    'footer.quickLinks': 'Enguudo Eziggumikirira',
    'footer.programs': 'Pulogulaamu',
    'footer.connect': 'Tunywezeeko',
    'footer.legal': 'Amateeka',
    'footer.privacy': 'Enkola y\'Ekyama',
    'footer.terms': 'Enkola y\'Okukozesa',
    'footer.rights': 'Eddembe lyonna lirekeddwa.',
    
    'cta.learnMore': 'Manya Ebisingawo',
    'cta.joinUs': 'Tweegatte',
    'cta.seePrograms': 'Laba Pulogulaamu',
    'cta.donate': 'Waayo Kati',
    'cta.getInvolved': 'Weegatte',
    'cta.readMore': 'Soma Ebisingawo',
    'cta.viewAll': 'Laba Byonna',
  },
  sw: {
    'restore.cta': 'Rejesha baba leo',
    'nav.about': 'Kuhusu',
    'nav.programs': 'Programu',
    'nav.forge': 'Forge',
    'nav.stories': 'Hadithi',
    'nav.events': 'Matukio',
    'nav.getInvolved': 'Jiunge Nasi',
    'nav.contact': 'Wasiliana',
    'nav.donate': 'Toa Mchango',
    
    'programs.beAMan': 'Kuwa Mwanaume',
    'programs.beAMan.desc': 'Wiki 12 za msingi',
    'programs.nurturingBonds': 'Kulisha Uhusiano',
    'programs.nurturingBonds.desc': 'Baba na watoto',
    'programs.mobileKanaabe': 'Mobile Kanaabe',
    'programs.mobileKanaabe.desc': 'Matembezi vijijini',
    
    'home.hero.badge': 'Mradi wa The Remnant Generation',
    'home.hero.title1': 'Kila Baba Muhimu.',
    'home.hero.title2': 'Kila Familia Inashinda.',
    'home.hero.cta1': 'Angalia Programu Zetu',
    'home.hero.cta2': 'Jiunge na Harakati',
    
    'home.impact.fathers': 'Mababu Waliorejesha',
    'home.impact.families': 'Familia Zilizoimarishwa',
    'home.impact.groups': 'Vikundi vya Forge Hai',
    
    'home.problem.stat1': '64% ya nyumba za Uganda hazina baba hai',
    'home.problem.stat2': 'Watoto 7 kati ya 10 wanakua bila mwongozo wa kiume',
    'home.problem.stat3': 'Ukosefu wa baba unaunganisha na umaskini 3× zaidi',
    'home.problem.quote': 'Hatuwajui mababu mmoja mmoja. Tunajenga undugu—vikundi vya Forge ambapo wanaume wananoa wanaume.',
    
    'home.programs.title': 'Jinsi Tunavyofanya Kazi',
    'home.programs.lede': 'Njia tatu. Dhamira moja: Kila baba ameandaliwa, kila familia nzima.',
    
    'footer.mission': 'Kurudisha mababu, kujenga upya familia nchini Uganda.',
    'footer.quickLinks': 'Viungo vya Haraka',
    'footer.programs': 'Programu',
    'footer.connect': 'Unganisha',
    'footer.legal': 'Kisheria',
    'footer.privacy': 'Sera ya Faragha',
    'footer.terms': 'Masharti ya Matumizi',
    'footer.rights': 'Haki zote zimehifadhiwa.',
    
    'cta.learnMore': 'Jifunze Zaidi',
    'cta.joinUs': 'Jiunge Nasi',
    'cta.seePrograms': 'Angalia Programu',
    'cta.donate': 'Toa Sasa',
    'cta.getInvolved': 'Jiunge',
    'cta.readMore': 'Soma Zaidi',
    'cta.viewAll': 'Angalia Zote',
  }
};

// Get current language from localStorage
function getCurrentLang() {
  return localStorage.getItem('fa-lang') || 'en';
}

// Set language and persist
function setCurrentLang(lang) {
  localStorage.setItem('fa-lang', lang);
  window.dispatchEvent(new Event('langchange'));
}

// Translate a key
function t(key, lang = getCurrentLang()) {
  return translations[lang]?.[key] || translations.en[key] || key;
}

// Hook for components
function useLang() {
  const [lang, setLang] = React.useState(getCurrentLang());
  
  React.useEffect(() => {
    const handler = () => setLang(getCurrentLang());
    window.addEventListener('langchange', handler);
    return () => window.removeEventListener('langchange', handler);
  }, []);
  
  return [lang, setCurrentLang];
}

window.t = t;
window.useLang = useLang;
window.getCurrentLang = getCurrentLang;
window.setCurrentLang = setCurrentLang;
