/**
 * Currency Symbols Constants
 *
 * Common currency symbols with their ISO codes for the currency element dropdown.
 * The list is sorted by popularity/common usage.
 */

export interface CurrencySymbolOption {
  code: string; // ISO 4217 currency code
  symbol: string; // Currency symbol
  name: string; // Full currency name
}

/**
 * List of common currency symbols
 * Sorted by popularity in e-commerce
 */
export const CURRENCY_SYMBOLS: CurrencySymbolOption[] = [
  // Major world currencies
  {code: "USD", symbol: "$", name: "US Dollar"},
  {code: "EUR", symbol: "€", name: "Euro"},
  {code: "GBP", symbol: "£", name: "British Pound"},
  {code: "JPY", symbol: "¥", name: "Japanese Yen"},
  {code: "CNY", symbol: "¥", name: "Chinese Yuan"},
  {code: "CHF", symbol: "CHF", name: "Swiss Franc"},
  {code: "CAD", symbol: "$", name: "Canadian Dollar"},
  {code: "AUD", symbol: "$", name: "Australian Dollar"},

  // European currencies
  {code: "SEK", symbol: "kr", name: "Swedish Krona"},
  {code: "NOK", symbol: "kr", name: "Norwegian Krone"},
  {code: "DKK", symbol: "kr", name: "Danish Krone"},
  {code: "PLN", symbol: "zł", name: "Polish Zloty"},
  {code: "CZK", symbol: "Kč", name: "Czech Koruna"},
  {code: "HUF", symbol: "Ft", name: "Hungarian Forint"},
  {code: "RON", symbol: "lei", name: "Romanian Leu"},
  {code: "BGN", symbol: "лв", name: "Bulgarian Lev"},
  {code: "HRK", symbol: "kn", name: "Croatian Kuna"},
  {code: "RUB", symbol: "₽", name: "Russian Ruble"},
  {code: "UAH", symbol: "₴", name: "Ukrainian Hryvnia"},
  {code: "TRY", symbol: "₺", name: "Turkish Lira"},

  // Asian currencies
  {code: "KRW", symbol: "₩", name: "South Korean Won"},
  {code: "INR", symbol: "₹", name: "Indian Rupee"},
  {code: "IDR", symbol: "Rp", name: "Indonesian Rupiah"},
  {code: "MYR", symbol: "RM", name: "Malaysian Ringgit"},
  {code: "SGD", symbol: "$", name: "Singapore Dollar"},
  {code: "HKD", symbol: "$", name: "Hong Kong Dollar"},
  {code: "TWD", symbol: "NT$", name: "Taiwan Dollar"},
  {code: "THB", symbol: "฿", name: "Thai Baht"},
  {code: "VND", symbol: "₫", name: "Vietnamese Dong"},
  {code: "PHP", symbol: "₱", name: "Philippine Peso"},
  {code: "PKR", symbol: "₨", name: "Pakistani Rupee"},
  {code: "BDT", symbol: "৳", name: "Bangladeshi Taka"},

  // Americas
  {code: "MXN", symbol: "$", name: "Mexican Peso"},
  {code: "BRL", symbol: "R$", name: "Brazilian Real"},
  {code: "ARS", symbol: "$", name: "Argentine Peso"},
  {code: "CLP", symbol: "$", name: "Chilean Peso"},
  {code: "COP", symbol: "$", name: "Colombian Peso"},
  {code: "PEN", symbol: "S/", name: "Peruvian Sol"},

  // Middle East & Africa
  {code: "AED", symbol: "د.إ", name: "UAE Dirham"},
  {code: "SAR", symbol: "﷼", name: "Saudi Riyal"},
  {code: "ILS", symbol: "₪", name: "Israeli Shekel"},
  {code: "EGP", symbol: "£", name: "Egyptian Pound"},
  {code: "ZAR", symbol: "R", name: "South African Rand"},
  {code: "NGN", symbol: "₦", name: "Nigerian Naira"},
  {code: "KES", symbol: "KSh", name: "Kenyan Shilling"},

  // Oceania
  {code: "NZD", symbol: "$", name: "New Zealand Dollar"},
  {code: "FJD", symbol: "$", name: "Fiji Dollar"},
];

/**
 * Get currency symbol by ISO code
 */
export function getCurrencySymbol(code: string): string {
  const currency = CURRENCY_SYMBOLS.find(
    (c) => c.code.toLowerCase() === code.toLowerCase()
  );
  return currency?.symbol ?? code;
}

/**
 * Get currency option by ISO code
 */
export function getCurrencyOption(code: string): CurrencySymbolOption | null {
  return (
    CURRENCY_SYMBOLS.find((c) => c.code.toLowerCase() === code.toLowerCase()) ??
    null
  );
}

/**
 * Get default currency from WooCommerce settings
 */
export function getWooCommerceCurrency(): {symbol: string; code: string} {
  const currency = window.oppbAdmin?.currency;
  return {
    symbol: currency?.symbol ?? "$",
    code: currency?.code ?? "USD",
  };
}
