export type Language = 'en' | 'am' | 'om' | 'fr';

const translations = {
  en: {
    nav: {
      home: 'Home',
      services: 'Services',
      about: 'About',
      contact: 'Contact',
      help: 'Help',
      bookNow: 'Book now',
    },
    home: {
      hero: 'Travel across the East Africa',
      heroSub: 'Experience seamless train travel from Ethiopia to Djibouti',
      cta: 'Start booking',
      searchNow: 'Search trips',
      features: 'Why choose EDR?',
      comfortable: 'Comfortable journey',
      comfortDesc: 'Modern coaches with seating and sleeping berths',
      affordable: 'Affordable pricing',
      affordableDesc: 'Competitive fares with discounts for families',
      safe: 'Safe and reliable',
      safeDesc: 'On-time arrivals with 24/7 customer support',
      fast: 'Quick booking',
      fastDesc: 'Book in minutes, pay with multiple methods',
    },
    services: {
      title: 'Our services',
      subtitle: 'Everything you need for a great journey',
      booking: 'Easy booking',
      bookingDesc: 'Simple online booking with instant confirmation',
      seats: 'Seat selection',
      seatsDesc: 'Choose from economy, standard, and VIP coaches',
      payment: 'Flexible payment',
      paymentDesc: 'Pay with Telebirr, CBE Birr, cards, or wallet',
      support: 'Customer support',
      supportDesc: 'Live chat and 24/7 assistance available',
      loyalty: 'Loyalty rewards',
      loyaltyDesc: 'Earn points and unlock exclusive benefits',
      tracking: 'Live tracking',
      trackingDesc: 'Real-time updates on your train journey',
    },
    about: {
      title: 'About EDR',
      subtitle: 'Connecting East Africa',
      mission: 'Our mission',
      missionText: 'To provide reliable, affordable, and comfortable train travel connecting Ethiopia and Djibouti.',
      network: 'Extensive network',
      networkText: '21 stations across Ethiopia and Djibouti with modern infrastructure.',
      comfort: 'Comfort first',
      comfortText: 'Modern coaches designed for your comfort with multiple classes.',
      eco: 'Eco-friendly',
      ecoText: 'Sustainable travel option that reduces carbon footprint.',
    },
    contact: {
      title: 'Get in touch',
      subtitle: 'We are here to help',
      email: 'Email',
      phone: 'Phone',
      address: 'Address',
      form: 'Send us a message',
      name: 'Full Name',
      emailField: 'Email address',
      subject: 'Subject',
      message: 'Message',
      send: 'Send message',
      sending: 'Sending...',
      success: 'Message sent successfully!',
      error: 'Failed to send message',
    },
    help: {
      title: 'Help and FAQs',
      subtitle: 'Find answers to common questions',
      bookingFaq: 'Booking questions',
      how: 'How do I book a ticket?',
      howAnswer: 'Visit our booking page, search for available trips, select your seats, and complete payment.',
      modify: 'Can I modify my booking?',
      modifyAnswer: 'Yes, you can modify bookings up to 24 hours before departure from your profile.',
      cancel: 'What is the cancellation policy?',
      cancelAnswer: 'Cancellations made 48 hours before departure receive full refund.',
      paymentFaq: 'Payment questions',
      payMethods: 'What payment methods do you accept?',
      payMethodsAnswer: 'We accept Telebirr, CBE Birr, eBirr, credit/debit cards, and wallet balance.',
      refund: 'When will I receive my refund?',
      refundAnswer: 'Refunds are processed within 5-7 business days.',
      other: 'Other questions',
      docs: 'What documents do I need?',
      docsAnswer: 'Valid national ID, passport, or travel permit required.',
      help: 'Still need help?',
      contact: 'Contact our support team',
    },
    footer: {
      about: 'About',
      support: 'Support',
      privacy: 'Privacy policy',
      terms: 'Terms of service',
      follow: 'Follow us',
      rights: 'All rights reserved.',
    },
  },
  am: {
    nav: {
      home: 'ቤት',
      services: 'አገልግሎቶች',
      about: 'ስለ ኛ',
      contact: 'አግኙን',
      help: 'ርዳታ',
      bookNow: 'አሁን ይመዝገቡ',
    },
    home: {
      hero: 'በምስራቅ አፍሪካ ውስጥ ይጓዙ',
      heroSub: 'ከኢትዮጵያ ወደ ጂቡቲ ello seamless train travel ያስተዋውቁ',
      cta: 'ቁጠባ ይጀምሩ',
      searchNow: 'ጉብኝቶች ይፈልጉ',
      features: 'ለምን ኢደር ይምረጡ?',
      comfortable: 'ምቹ ጉዞ',
      comfortDesc: 'ዘመናዊ ሕንፃዎች ወንበር እና ማተም ወራጆች ጋር',
      affordable: 'ርካሽ ዋጋ',
      affordableDesc: 'ለቤተሰቦች ምጣኔ ሞገድ እና ቅናሾች',
      safe: 'ደህንነተኛ & አስተማማኝ',
      safeDesc: 'በጊዜ ምጡና 24/7 ደንበኛ ድጋፍ',
      fast: 'ፈጣን ቁጠባ',
      fastDesc: 'በደቂቃዎች ይመዝገቡ፣ ብዙ ዘዴዎችን ይከፍሉ',
    },
    services: {
      title: 'አገልግሎቶቻችን',
      subtitle: 'ታላቅ ጉዞ ለሚፈልጉ ሁሉ ነገር',
      booking: 'ቀላል ቁጠባ',
      bookingDesc: 'ቀላል የመስመር ላይ ቁጠባ ወቅታዊ ማረጋገጫ ጋር',
      seats: 'ወንበር ምርጫ',
      seatsDesc: 'ኢኮኖሚ፣ መደበኛ እና VIP ሕንፃዎች ምረጡ',
      payment: '유연한ከጊዜ ወደ ጊዜ ክፍያ',
      paymentDesc: 'Telebirr፣ CBE Birr፣ ካርዶች ወይም ዋሌት ይከፍሉ',
      support: 'ደንበኛ ድጋፍ',
      supportDesc: 'ライブ ቻት እና 24/7 ረዳት ይገኛሉ',
      loyalty: 'ታማኝነት ሽልማቶች',
      loyaltyDesc: 'ነጥቦች ያዙ እና ብቁ ጥቅሞች ያስከፍቱ',
      tracking: 'ライブ ትንተና',
      trackingDesc: 'የእርስዎ ባቡር ጉዞ ውስጥ ወቅታዊ ማሻሻያዎች',
    },
    about: {
      title: 'ስለ ኢትዮጵያ-ጂቡቲ ባቡር',
      subtitle: 'ምስራቅ አፍሪካ ያገናኙ',
      mission: 'ራሳችን መጠን',
      missionText: 'ኢትዮጵያ እና ጂቡቲን የሚያገናኙ አስተማማኝ፣ ርካሽ እና ምቹ ባቡር ጉዞ ይሰጡ።',
      network: 'ሰፊ አውታር',
      networkText: 'ኢትዮጵያ እና ጂቡቲ ውስጥ 21 ጣቢያዎች ዘመናዊ መሰረተ ልማት ጋር።',
      comfort: 'ምቹ ሞላላ',
      comfortText: 'ብዙ ክፍሎች ጋር የእርስዎ comfort ለ ዲዛይን ዘመናዊ ሕንፃዎች።',
      eco: 'ପରିବେश __ 친화적',
      ecoText: 'ካርቦን እግድ ሪሞት የሚቀንስ sustainable ጉዞ አማራጭ።',
    },
    contact: {
      title: 'ከኛ ጋር ግንኙነት ወስጥ ደርሱ',
      subtitle: 'እኛ ረድ ለ ልንሆን ሞገዱ',
      email: 'ኢሜይል',
      phone: 'ስልክ',
      address: 'አድራሻ',
      form: 'ለኛ መልእክት ይላኩ',
      name: 'ሙሉ ስም',
      emailField: 'ኢሜይል አድራሻ',
      subject: 'ርዕስ',
      message: 'መልእክት',
      send: 'መልእክት ይላኩ',
      sending: 'በመላክ ላይ...',
      success: 'መልእክት በተሳካ ተልኩ!',
      error: 'መልእክት ወደ ላክ ያልተሳካ',
    },
    help: {
      title: 'ርዳታ & FAQs',
      subtitle: 'ከ general ጥያቄዎች የሚመለስ መልስ ይፈልጉ',
      bookingFaq: 'ቁጠባ ጥያቄዎች',
      how: 'ስንት በየት ላይ ቁጠባ?',
      howAnswer: 'ቁጠባ ገጽ ይጎብኙ፣ ዞሯ ለ ይፈልጉ ፣ ወንበር ይምረጡ ዝሕ ክፍያ።',
      modify: 'እኔ ቁጠባ እንደገና ማስተካከል ይችላሉ?',
      modifyAnswer: 'አዎ፣ መውጫ 24 ሰዓታት በፊት ቁጠባ እንደገና ማስተካከል ይችላሉ።',
      cancel: 'cancellation ወሳኔ ምንድ ነው?',
      cancelAnswer: 'አስመልከት 48 ሰዓታት በፊት አውጪ ሙሉ መልስ ያገኛሉ።',
      paymentFaq: 'ክፍያ ጥያቄዎች',
      payMethods: 'Telebirr, CBE Birr, eBirr, ክレジット/ዲቢት ካርዶች, እና ዋሌት ሚዛን ኤ acceptedይገቡ।',
      payMethodsAnswer: 'Telebirr, CBE Birr, eBirr, credit/debit ካርዶች፣ እና ዋሌት ሚዛን ยอมrับ',
      refund: 'my አሌ ሥራ refund?',
      refundAnswer: 'Refund በ 5-7 ሥራ ቀናት ውስጥ ተወስኖልት።',
      other: 'ሌሎች ጥያቄዎች',
      docs: 'ኔ ወሰደ ምን documentation?',
      docsAnswer: 'ዋጋ ብሔር ID፣ ፓስፖርት ወይም ጉዞ permit አስፈላጊ።',
      help: 'አሁንም ረዳታ ፈልገው?',
      contact: 'ደንበኛ ድጋፍ ቡድን ጋር ማንቲ',
    },
    footer: {
      about: 'ስለ',
      contact: 'አግኙን',
      privacy: 'ግላዊነት ፖሊሲ',
      terms: 'service ውል',
      follow: 'ከሱ ተከተሉ',
      rights: 'ሁሉ ሙሉ።',
    },
  },
  om: {
    nav: {
      home: 'Mana',
      services: 'Tajaajilaa',
      about: 'Waa',
      contact: 'Nu Ilaali',
      help: 'Gargaarsa',
      bookNow: 'Amma Qindeessuu',
    },
    home: {
      hero: 'Kaasaa Baafata Gidiraa',
      heroSub: 'Kunoosni caraa qammateen Itoophiyaa hoo Jibuuraa jira.',
      cta: 'Qindeessuu Jalqabi',
      searchNow: 'Naannoo Barbaadi',
      features: 'Maaliif EDR Filachuu?',
      comfortable: 'Wantaa Mijataa',
      comfortDesc: 'Haalaan biraa konkolaata mooniisa seeda jira.',
      affordable: 'Gatii Gabbina',
      affordableDesc: 'Karoora muummichaa jala maallaqa qabeenya.',
      safe: 'Nageenya & Jidha',
      safeDesc: 'Yeroo jilbaa dhumaasuu fi gargaarsa 24/7 deggara.',
      fast: 'Qindeessuu Abadii',
      fastDesc: 'Yeroo giddu gidduu qindeessuu, mallaatoo ijaa gadii.',
    },
    services: {
      title: 'Tajaajilaa Keenya',
      subtitle: 'Waa waliigalaan wantoota gid caraa mijataa',
      booking: 'Qindeessuu Salphaa',
      bookingDesc: 'Qindeessuu interneetii salphaa jidha gaafatama',
      seats: 'Filannoo Teessaa',
      seatsDesc: 'Ekonomii, idileessaa jala VIP konkolaata filachuu',
      payment: 'Maallaqa Giddu Gidduu',
      paymentDesc: 'Telebirr, CBE Birr, kaardii ykn wallaattii jalqabi',
      support: 'Gargaarsa Fayyadhaa',
      supportDesc: 'Haftuu liixii jala gargaarsa 24/7 jira',
      loyalty: 'Gammachiisa Jidha',
      loyaltyDesc: 'Qooda qabu jila waan gaarii gargaara',
      tracking: 'Jidha Liixii',
      trackingDesc: 'Jiraataa kunoosni caraa qammateen gammachisu',
    },
    about: {
      title: 'Waa Baafata Itoophiyaa-Jibuuraa',
      subtitle: 'Baafata Gidiraa Yoo Wal Qabu',
      mission: 'Kora Keenya',
      missionText: 'Nageenya jidha, gatii gabbina, jidha mijataa Itoophiyaa jala Jibuuraa tajaajili.',
      network: 'Shabdalee Babaasaa',
      networkText: '21 taasaa Itoophiyaa jala Jibuuraa keessatti konkolaata biraa.',
      comfort: 'Mirga Jalqabaa',
      comfortText: 'Konkolaata mooniisa mijataa kee waraqsa gidduu jira.',
      eco: 'Kaasaalee Mijataa',
      ecoText: 'Caraa ijaa yoo sadarka karbuuni muraa gidduu.',
    },
    contact: {
      title: 'Nu Ilaali',
      subtitle: 'Nu gargaaruufi barbaachisaa',
      email: 'Imeelii',
      phone: 'Bilbila',
      address: 'Tuulaa',
      form: 'Naaraan Itti Ergi',
      name: 'Maqaa Guutuu',
      emailField: 'Imeelii tuula',
      subject: 'Mata',
      message: 'Itti Ergi',
      send: 'Naaraan Ergi',
      sending: 'Erguun jira...',
      success: 'Naaraan gaafatama jira!',
      error: 'Naaraan erguu hin raasuu',
    },
    help: {
      title: 'Gargaarsa & FAQs',
      subtitle: 'Gaaffii guutuu jala deebii barbaadi',
      bookingFaq: 'Gaaffii Qindeessuu',
      how: 'Akkamitti qindeessuu?',
      howAnswer: 'Fuula qindeessuu dhugi, naannoo barbaadi, teessaa filachuu, maallaqa xumura.',
      modify: 'Qindeessuu koo maratti jidha adeemsa?',
      modifyAnswer: 'Eenyee, walta 24 sa itti fufu qindeessuu maratti jidha adeemsa dandeenya.',
      cancel: 'Hoggansa gaafatama maal jira?',
      cancelAnswer: 'Walta 48 sa itti fufu walitti erga dhumaasuu guutuu arguu jidha.',
      paymentFaq: 'Gaaffii Maallaqa',
      payMethods: 'Maallaqa keessaa maallaqa hayyamaa?',
      payMethodsAnswer: 'Telebirr, CBE Birr, eBirr, kaardii kreediitii/dibati, jala wallaattii haa jira.',
      refund: 'Yeroo maallaqa deebina?',
      refundAnswer: 'Maallaaq 5-7 guyyaa hojii keessatti deebi.',
      other: 'Gaaffii Biraa',
      docs: 'Waraqaa maal barbaachisa?',
      docsAnswer: 'Kaardii ID bakka, paaspoortii ykn walii haa barbaachisaa.',
      help: 'Haaluma facaasin gargaarsa Barbaadi?',
      contact: 'Gargaarsa fayyadhaa mana waliin ilaali',
    },
    footer: {
      about: 'Waa',
      contact: 'Nu Ilaali',
      privacy: 'Kabaja Kunnamuu',
      terms: 'Seera Tajaajila',
      follow: 'Isaa Hordofu',
      rights: 'Hundi moodeewwan.',
    },
  },
  fr: {
    nav: {
      home: 'Accueil',
      services: 'Services',
      about: 'À Propos',
      contact: 'Contact',
      help: 'Aide',
      bookNow: 'Réserver Maintenant',
    },
    home: {
      hero: 'Voyagez à travers l\'Afrique de l\'Est',
      heroSub: 'Découvrez les voyages en train sans interruption d\'Éthiopie à Djibouti',
      cta: 'Commencer la Réservation',
      searchNow: 'Rechercher des Trajets',
      features: 'Pourquoi Choisir EDR?',
      comfortable: 'Voyage Confortable',
      comfortDesc: 'Autobus modernes avec sièges et couchettes',
      affordable: 'Prix Abordables',
      affordableDesc: 'Tarifs compétitifs avec réductions pour familles',
      safe: 'Sûr & Fiable',
      safeDesc: 'Arrivées à l\'heure avec support client 24/7',
      fast: 'Réservation Rapide',
      fastDesc: 'Réservez en minutes, payez par plusieurs méthodes',
    },
    services: {
      title: 'Nos Services',
      subtitle: 'Tout ce dont vous avez besoin pour un excellent voyage',
      booking: 'Réservation Facile',
      bookingDesc: 'Réservation en ligne simple avec confirmation instantanée',
      seats: 'Sélection des Sièges',
      seatsDesc: 'Choisissez parmi les autobus économique, standard et VIP',
      payment: 'Paiement Flexible',
      paymentDesc: 'Payez avec Telebirr, CBE Birr, cartes ou portefeuille',
      support: 'Support Client',
      supportDesc: 'Chat en direct et assistance 24/7 disponibles',
      loyalty: 'Récompenses de Fidélité',
      loyaltyDesc: 'Gagnez des points et déverrouillez des avantages exclusifs',
      tracking: 'Suivi en Direct',
      trackingDesc: 'Mises à jour en temps réel de votre voyage en train',
    },
    about: {
      title: 'À Propos du Chemin de Fer Éthiopie-Djibouti',
      subtitle: 'Connecter l\'Afrique de l\'Est',
      mission: 'Notre Mission',
      missionText: 'Offrir des voyages en train fiables, abordables et confortables reliant l\'Éthiopie et Djibouti.',
      network: 'Réseau Étendu',
      networkText: '21 gares à travers l\'Éthiopie et Djibouti avec infrastructure moderne.',
      comfort: 'Confort D\'Abord',
      comfortText: 'Autobus modernes conçus pour votre confort avec plusieurs catégories.',
      eco: 'Écologique',
      ecoText: 'Option de voyage durable qui réduit l\'empreinte carbone.',
    },
    contact: {
      title: 'Contactez-Nous',
      subtitle: 'Nous sommes là pour vous aider',
      email: 'Email',
      phone: 'Téléphone',
      address: 'Adresse',
      form: 'Envoyez-Nous un Message',
      name: 'Nom Complet',
      emailField: 'Adresse E-mail',
      subject: 'Sujet',
      message: 'Message',
      send: 'Envoyer le Message',
      sending: 'Envoi en cours...',
      success: 'Message envoyé avec succès!',
      error: 'Échec de l\'envoi du message',
    },
    help: {
      title: 'Aide & Questions Fréquentes',
      subtitle: 'Trouvez des réponses aux questions courantes',
      bookingFaq: 'Questions de Réservation',
      how: 'Comment réserver un billet?',
      howAnswer: 'Visitez notre page de réservation, recherchez les trajets disponibles, sélectionnez vos sièges et complétez le paiement.',
      modify: 'Puis-je modifier ma réservation?',
      modifyAnswer: 'Oui, vous pouvez modifier les réservations jusqu\'à 24 heures avant le départ.',
      cancel: 'Quelle est la politique d\'annulation?',
      cancelAnswer: 'Les annulations effectuées 48 heures avant le départ reçoivent un remboursement complet.',
      paymentFaq: 'Questions de Paiement',
      payMethods: 'Quels modes de paiement acceptez-vous?',
      payMethodsAnswer: 'Nous acceptons Telebirr, CBE Birr, eBirr, cartes bancaires et portefeuille.',
      refund: 'Quand recevrai-je mon remboursement?',
      refundAnswer: 'Les remboursements sont traités dans les 5-7 jours ouvrables.',
      other: 'Autres Questions',
      docs: 'Quels documents dois-je avoir?',
      docsAnswer: 'Une carte d\'identité nationale, un passeport ou un permis de voyage valide est requis.',
      help: 'Avez-vous toujours besoin d\'aide?',
      contact: 'Contactez notre équipe d\'assistance',
    },
    footer: {
      about: 'À Propos',
      contact: 'Contact',
      privacy: 'Politique de Confidentialité',
      terms: 'Conditions d\'Utilisation',
      follow: 'Suivez-Nous',
      rights: 'Tous droits réservés.',
    },
  },
};

export function getTranslation(lang: Language, key: string): string {
  const keys = key.split('.');
  let value: any = translations[lang];
  for (const k of keys) {
    value = value?.[k];
  }
  return value || key;
}

export function useLanguage() {
  const getLang = (): Language => {
    if (typeof window === 'undefined') return 'en';
    return (localStorage.getItem('language') as Language) || 'en';
  };

  const setLang = (lang: Language) => {
    localStorage.setItem('language', lang);
    window.dispatchEvent(new CustomEvent('languageChange', { detail: lang }));
  };

  return { getLang, setLang };
}
