import { useOmni } from "@/components/OmniSyncProvider";

export const translations = {
  en: {
    Index: {
      title: "Verified Access",
      subtitle: "JUMPA Global B2B Real-time Infrastructure",
      credentials: "Credentials",
      quantum_qr: "Quantum QR",
      email_placeholder: "Email Address",
      password_placeholder: "Password",
      persistent_session: "Persistent Session",
      reset_key: "Reset Key?",
      enter_multiverse: "Enter Multiverse",
      initialize_account: "Initialize Account",
      instant_sync: "Instant Sync Auth",
      scan_instructions: "Scan this quantum hash with your JUMPA Mobile App for zero-password entry.",
      new_to_multiverse: "New to the Multiverse?",
      access_now: "Access Now — It's Free",
      known_identity: "Known Identity?",
      sign_in: "Access Now",
      quantum_vault_sync: "Quantum Vault Synchronized"
    },
    Dashboard: {
      welcome: "Welcome to the Multiverse",
      mesh_sync: "Mesh Sync",
      active_nodes: "Active Nodes",
      launch_app: "Launch Application",
      engine_status: "Engine Status",
      realtime_telemetry: "Real-time Telemetry"
    },
    Billing: {
      title: "Billing Matrix",
      package: "Package",
      price: "Price",
      features: "Features",
      checkout: "Pay Now",
      currency: "Currency",
      payment_gateway: "Payment Gateway",
      subscription: "Subscription",
      upgrade: "Upgrade Plan"
    }
  },
  id: {
    Index: {
      title: "Akses Terverifikasi",
      subtitle: "Infrastruktur Real-time Global B2B JUMPA",
      credentials: "Kredensial",
      quantum_qr: "Quantum QR",
      email_placeholder: "Alamat Email",
      password_placeholder: "Kata Sandi",
      persistent_session: "Sesi Persisten",
      reset_key: "Reset Kunci?",
      enter_multiverse: "Masuk ke Multiverse",
      initialize_account: "Inisialisasi Akun",
      instant_sync: "Autentikasi Sinkron Instan",
      scan_instructions: "Pindai hash quantum ini dengan Aplikasi Mobile JUMPA Anda untuk akses tanpa kata sandi.",
      new_to_multiverse: "Baru di Multiverse?",
      access_now: "Akses Sekarang — Gratis",
      known_identity: "Identitas Dikenal?",
      sign_in: "Masuk Sekarang",
      quantum_vault_sync: "Vault Quantum Tersinkronisasi"
    },
    Dashboard: {
      welcome: "Selamat Datang di Multiverse",
      mesh_sync: "Sinkronisasi Mesh",
      active_nodes: "Node Aktif",
      launch_app: "Luncurkan Aplikasi",
      engine_status: "Status Mesin",
      realtime_telemetry: "Telemetri Real-time"
    },
    Billing: {
      title: "Matriks Penagihan",
      package: "Paket",
      price: "Harga",
      features: "Fitur",
      checkout: "Bayar Sekarang",
      currency: "Mata Uang",
      payment_gateway: "Gerbang Pembayaran",
      subscription: "Langganan",
      upgrade: "Tingkatkan Paket"
    }
  }
};

export function useDictionary() {
  const { locale } = useOmni();

  const t = (path: string) => {
    const keys = path.split(".");
    let current: any = translations[locale];
    
    // Fallback logic
    if (!current && locale !== 'id') {
       current = translations['id'];
    }

    for (const key of keys) {
      if (current[key] !== undefined) {
        current = current[key];
      } else {
        return path; // Return key string if missing
      }
    }
    return current;
  };

  return { t };
}
