/**
 * Internationalization Service
 * Support: English, Spanish, French, Swahili, Tagalog, Hindi
 */
'use strict';

const translations = {
  en: {
    welcome: "👋 Welcome to Loopuman!\n\nThe Human Layer for AI.\nComplete tasks, get paid in 8 seconds.",
    find_work: "🔍 Find Work",
    my_tasks: "💼 My Tasks",
    post_task: "➕ Post Task",
    wallet: "💰 Wallet",
    profile: "👤 Profile",
    task_accepted: "✅ Task Accepted!",
    task_submitted: "✅ Work Submitted!",
    task_approved: "🎉 Payment Received!",
    no_tasks: "No tasks available right now.",
    balance: "Balance",
    available: "Available",
    pending: "Pending",
    withdraw: "Withdraw",
    deposit: "Deposit",
    back: "🔙 BACK",
    confirm: "✅ Confirm",
    cancel: "❌ Cancel",
    error_try_again: "❌ Error. Please try again.",
    min_withdrawal: "Minimum withdrawal:",
    daily_limit: "Daily limit:",
    trust_score: "Trust Score",
    tasks_completed: "Tasks Completed",
    rating: "Rating",
    dispute: "⚠️ Raise Dispute",
    dispute_submitted: "Your dispute has been submitted. We'll review within 24 hours.",
  },
  es: {
    welcome: "👋 ¡Bienvenido a Loopuman!\n\nLa Capa Humana para IA.\nCompleta tareas, cobra en 8 segundos.",
    find_work: "🔍 Buscar Trabajo",
    my_tasks: "💼 Mis Tareas",
    post_task: "➕ Publicar Tarea",
    wallet: "💰 Billetera",
    profile: "👤 Perfil",
    task_accepted: "✅ ¡Tarea Aceptada!",
    task_submitted: "✅ ¡Trabajo Enviado!",
    task_approved: "🎉 ¡Pago Recibido!",
    no_tasks: "No hay tareas disponibles ahora.",
    balance: "Saldo",
    available: "Disponible",
    pending: "Pendiente",
    withdraw: "Retirar",
    deposit: "Depositar",
    back: "🔙 ATRÁS",
    confirm: "✅ Confirmar",
    cancel: "❌ Cancelar",
    error_try_again: "❌ Error. Intenta de nuevo.",
    min_withdrawal: "Retiro mínimo:",
    daily_limit: "Límite diario:",
    trust_score: "Puntuación de Confianza",
    tasks_completed: "Tareas Completadas",
    rating: "Calificación",
    dispute: "⚠️ Abrir Disputa",
    dispute_submitted: "Tu disputa ha sido enviada. Revisaremos en 24 horas.",
  },
  sw: {
    welcome: "👋 Karibu Loopuman!\n\nSafu ya Binadamu kwa AI.\nKamilisha kazi, lipa ndani ya sekunde 8.",
    find_work: "🔍 Tafuta Kazi",
    my_tasks: "💼 Kazi Zangu",
    post_task: "➕ Weka Kazi",
    wallet: "💰 Mkoba",
    profile: "👤 Wasifu",
    task_accepted: "✅ Kazi Imekubaliwa!",
    task_submitted: "✅ Kazi Imetumwa!",
    task_approved: "🎉 Malipo Yamepokelewa!",
    no_tasks: "Hakuna kazi zinazopatikana sasa.",
    balance: "Salio",
    available: "Inapatikana",
    pending: "Inasubiri",
    withdraw: "Toa",
    deposit: "Weka",
    back: "🔙 RUDI",
    confirm: "✅ Thibitisha",
    cancel: "❌ Ghairi",
    error_try_again: "❌ Hitilafu. Jaribu tena.",
    dispute: "⚠️ Fungua Mzozo",
  },
  tl: {
    welcome: "👋 Maligayang pagdating sa Loopuman!\n\nAng Human Layer para sa AI.\nKumpleto ng mga gawain, makakuha ng bayad sa 8 segundo.",
    find_work: "🔍 Maghanap ng Trabaho",
    my_tasks: "💼 Aking Mga Gawain",
    post_task: "➕ Mag-post ng Gawain",
    wallet: "💰 Pitaka",
    profile: "👤 Profile",
    task_accepted: "✅ Tinanggap ang Gawain!",
    task_submitted: "✅ Naisumite ang Trabaho!",
    task_approved: "🎉 Natanggap ang Bayad!",
    no_tasks: "Walang available na gawain ngayon.",
    balance: "Balanse",
    withdraw: "Mag-withdraw",
    deposit: "Magdeposito",
    back: "🔙 BUMALIK",
    confirm: "✅ Kumpirmahin",
    cancel: "❌ Kanselahin",
  },
  hi: {
    welcome: "👋 Loopuman में आपका स्वागत है!\n\nAI के लिए मानव परत।\nकार्य पूरे करें, 8 सेकंड में भुगतान पाएं।",
    find_work: "🔍 काम खोजें",
    my_tasks: "💼 मेरे कार्य",
    post_task: "➕ कार्य पोस्ट करें",
    wallet: "💰 वॉलेट",
    profile: "👤 प्रोफाइल",
    task_accepted: "✅ कार्य स्वीकृत!",
    task_submitted: "✅ काम जमा किया!",
    task_approved: "🎉 भुगतान प्राप्त!",
    back: "🔙 वापस",
    confirm: "✅ पुष्टि करें",
    cancel: "❌ रद्द करें",
  },
  fr: {
    welcome: "👋 Bienvenue sur Loopuman!\n\nLa Couche Humaine pour l'IA.\nComplétez des tâches, soyez payé en 8 secondes.",
    find_work: "🔍 Chercher du Travail",
    my_tasks: "💼 Mes Tâches",
    post_task: "➕ Publier une Tâche",
    wallet: "💰 Portefeuille",
    profile: "👤 Profil",
    task_accepted: "✅ Tâche Acceptée!",
    task_submitted: "✅ Travail Soumis!",
    task_approved: "🎉 Paiement Reçu!",
    back: "🔙 RETOUR",
    confirm: "✅ Confirmer",
    cancel: "❌ Annuler",
  }
};

function t(key, lang = 'en') {
  return translations[lang]?.[key] || translations.en[key] || key;
}

function detectLanguage(telegramLangCode) {
  const map = { en: 'en', es: 'es', sw: 'sw', tl: 'tl', hi: 'hi', fr: 'fr', fil: 'tl' };
  return map[telegramLangCode] || 'en';
}

function getSupportedLanguages() {
  return Object.keys(translations);
}

module.exports = { t, translations, detectLanguage, getSupportedLanguages };
