import { LocationData } from "./location"; export interface CurrencyData { symbol: string; code: string; name: string; monthlyPrice: number; annualPrice: number; } const DEFAULT_CURRENCY: CurrencyData = { symbol: "US$", code: "USD", name: "US Dollars", monthlyPrice: 12, annualPrice: 9.6, }; // Simplified currency map: country code (lowercase) -> { code, symbol, rate, name } const currencyMap: Record = { us: { code: "USD", symbol: "US$", rate: 1, name: "US Dollars" }, au: { code: "AUD", symbol: "AU$", rate: 1.5, name: "Australian Dollars" }, gb: { code: "GBP", symbol: "£", rate: 0.8, name: "British Pounds" }, ca: { code: "CAD", symbol: "CA$", rate: 1.35, name: "Canadian Dollars" }, nz: { code: "NZD", symbol: "NZ$", rate: 1.65, name: "New Zealand Dollars" }, in: { code: "INR", symbol: "₹", rate: 83.5, name: "Indian Rupees" }, sg: { code: "SGD", symbol: "SG$", rate: 1.35, name: "Singapore Dollars" }, jp: { code: "JPY", symbol: "JP¥", rate: 152, name: "Japanese Yen" }, de: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, fr: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, es: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, it: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, nl: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, be: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, ie: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, at: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, fi: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, pt: { code: "EUR", symbol: "€", rate: 0.93, name: "Euros" }, se: { code: "SEK", symbol: "kr", rate: 10.5, name: "Swedish Krona" }, dk: { code: "DKK", symbol: "kr", rate: 7, name: "Danish Krone" }, no: { code: "NOK", symbol: "kr", rate: 10.8, name: "Norwegian Krone" }, pl: { code: "PLN", symbol: "zł", rate: 4, name: "Polish Złoty" }, cn: { code: "CNY", symbol: "CN¥", rate: 7.2, name: "Chinese Yuan" }, kr: { code: "KRW", symbol: "₩", rate: 1350, name: "South Korean Won" }, br: { code: "BRL", symbol: "R$", rate: 5, name: "Brazilian Real" }, mx: { code: "MXN", symbol: "MX$", rate: 16.8, name: "Mexican Pesos" }, za: { code: "ZAR", symbol: "R", rate: 18.5, name: "South African Rand" }, ph: { code: "PHP", symbol: "₱", rate: 56.5, name: "Philippine Pesos" }, my: { code: "MYR", symbol: "RM", rate: 4.75, name: "Malaysian Ringgit" }, th: { code: "THB", symbol: "฿", rate: 36.5, name: "Thai Baht" }, vn: { code: "VND", symbol: "₫", rate: 25000, name: "Vietnamese Đồng" }, id: { code: "IDR", symbol: "Rp", rate: 16000, name: "Indonesian Rupiah" }, tr: { code: "TRY", symbol: "₺", rate: 32.5, name: "Turkish Lira" }, ru: { code: "RUB", symbol: "₽", rate: 93, name: "Russian Rubles" }, il: { code: "ILS", symbol: "₪", rate: 3.75, name: "Israeli New Shekel" }, ua: { code: "UAH", symbol: "₴", rate: 39, name: "Ukrainian Hryvnia" }, }; export function getCurrencyForLocation(location: LocationData | null): CurrencyData { if (!location || !location.countryCode) { return DEFAULT_CURRENCY; } const country = location.countryCode.toLowerCase(); const currencyInfo = currencyMap[country]; if (!currencyInfo) { // If not in our map but we have countryCode, maybe it's Euro? const euroCountries = ["el", "bg", "hr", "sk", "sl", "lt", "lv", "ee", "ro", "hu", "cz"]; if (euroCountries.includes(country)) { return { symbol: "€", code: "EUR", name: "Euros", monthlyPrice: 11, annualPrice: 8.8, }; } return DEFAULT_CURRENCY; } const baseMonthly = 12; const rawMonthly = baseMonthly * (currencyInfo.rate || 1); let monthlyPrice = Math.round(rawMonthly); if (monthlyPrice < 100) { monthlyPrice = Math.round(rawMonthly * 2) / 2; } const annualPrice = monthlyPrice * 0.8; return { symbol: currencyInfo.symbol, code: currencyInfo.code, name: currencyInfo.name, monthlyPrice, annualPrice, }; }