const COUNTRY_DATA = {
    US: "USD",
    GB: "GBP",
    CN: "CNY",
    JP: "JPY",
    DE: "EUR",
    IN: "INR",
    FR: "EUR",
    CA: "CAD",
    AU: "AUD",
    KR: "KRW",
    IT: "EUR",
    BR: "BRL",
    ES: "EUR",
    NL: "EUR",
    CH: "CHF",
    SE: "SEK",
    SG: "SGD",
    HK: "HKD",
    AE: "AED",
    SA: "SAR",
    PK: "PKR",
    AR: "ARS",
    AT: "EUR",
    BD: "BDT",
    BE: "EUR",
    CO: "COP",
    CY: "EUR",
    CZ: "CZK",
    DK: "DKK",
    EG: "EGP",
    FI: "EUR",
    HU: "HUF",
    IE: "EUR",
    IL: "ILS",
    LK: "LKR",
    MX: "MXN",
    MY: "MYR",
    NG: "NGN",
    NO: "NOK",
    PL: "PLN",
    PT: "EUR",
    QA: "QAR",
    RU: "RUB",
    TR: "TRY",
    TW: "TWD",
    ZA: "ZAR"
};

const DEFAULT_COUNTRY_NAMES = {
    US: "United States",
    GB: "United Kingdom",
    CN: "China",
    JP: "Japan",
    DE: "Germany",
    IN: "India",
    FR: "France",
    CA: "Canada",
    AU: "Australia",
    KR: "South Korea",
    IT: "Italy",
    BR: "Brazil",
    ES: "Spain",
    NL: "Netherlands",
    CH: "Switzerland",
    SE: "Sweden",
    SG: "Singapore",
    HK: "Hong Kong",
    AE: "United Arab Emirates",
    SA: "Saudi Arabia",
    PK: "Pakistan",
    AR: "Argentina",
    AT: "Austria",
    BD: "Bangladesh",
    BE: "Belgium",
    CO: "Colombia",
    CY: "Cyprus",
    CZ: "Czech Republic",
    DK: "Denmark",
    EG: "Egypt",
    FI: "Finland",
    HU: "Hungary",
    IE: "Ireland",
    IL: "Israel",
    LK: "Sri Lanka",
    MX: "Mexico",
    MY: "Malaysia",
    NG: "Nigeria",
    NO: "Norway",
    PL: "Poland",
    PT: "Portugal",
    QA: "Qatar",
    RU: "Russia",
    TR: "Turkey",
    TW: "Taiwan",
    ZA: "South Africa"
};

const COUNTRIES = {};

Object.keys(COUNTRY_DATA).forEach(code => {
    Object.defineProperty(COUNTRIES, code, {
        enumerable: true,
        get() {
            return {
                get name() {
                    return getLang(`market_data.countries.${code}`, DEFAULT_COUNTRY_NAMES[code]);
                },
                currency: COUNTRY_DATA[code]
            };
        }
    });
});

const DEFAULT_SECTORS = {
    "Commercial Services": "Commercial Services",
    "Communications": "Communications",
    "Consumer Durables": "Consumer Durables",
    "Consumer Non-Durables": "Consumer Non-Durables",
    "Consumer Services": "Consumer Services",
    "Distribution Services": "Distribution Services",
    "Electronic Technology": "Electronic Technology",
    "Energy Minerals": "Energy Minerals",
    "Non-Energy Minerals": "Non-Energy Minerals",
    "Finance": "Finance",
    "Government Sector": "Government Sector",
    "Health Services": "Health Services",
    "Health Technology": "Health Technology",
    "Industrial Services": "Industrial Services",
    "Miscellaneous": "Miscellaneous",
    "Process Industries": "Process Industries",
    "Producer Manufacturing": "Producer Manufacturing",
    "Retail Trade": "Retail Trade",
    "Technology Services": "Technology Services",
    "Transportation": "Transportation",
    "Utilities": "Utilities"
};

const SECTORS = {};

Object.keys(DEFAULT_SECTORS).forEach(key => {
    Object.defineProperty(SECTORS, key, {
        enumerable: true,
        get() {
            return getLang(`market_data.sectors.${key}`, DEFAULT_SECTORS[key]);
        }
    });
});

Object.defineProperty(SECTORS, "all", {
    enumerable: true,
    get() {
        return getLang("menu_search.dropdowns.all_sectors", "All Sectors");
    }
});

const DEFAULT_SUB_TYPES = {
    crypto: {
        spot: "Spot",
        swap: "Swap",
        futures: "Futures",
        index: "Index",
        dominance: "Dominance"
    },
    forex: {
        spot: "Spot",
        synthetic: "Synthetic"
    },
    stock: {
        common: "Common",
        preferred: "Preferred",
        dr: "Depository Receipt",
        structured: "Structured"
    },
    fund: {
        closedend: "Closedend",
        etf: "ETF",
        mutual: "Mutual",
        reit: "Reit",
        unit: "Unit",
        trust: "Trust"
    }
};

const DEFAULT_CRYPTO_TYPES = {
    crypto: "CEX",
    coin: "Coins"
};

const createSubTypeGetter = (category, defaults) => {
    const obj = {};
    Object.keys(defaults).forEach(key => {
        Object.defineProperty(obj, key, {
            enumerable: true,
            get() {
                return getLang(`market_data.${category}.sub_type.${key}`, defaults[key]);
            }
        });
    });
    return obj;
};

const createCryptoTypeGetter = () => {
    const obj = {};
    Object.keys(DEFAULT_CRYPTO_TYPES).forEach(key => {
        Object.defineProperty(obj, key, {
            enumerable: true,
            get() {
                return getLang(`market_data.crypto.type.${key}`, DEFAULT_CRYPTO_TYPES[key]);
            }
        });
    });
    return obj;
};

const MARKET_DATA = {
    crypto: {
        exchange: [ {
            label: "Crypto Coins",
            value: "crypto",
            icon: "crypto"
        }, {
            label: "Crypto Cap",
            value: "CRYPTOCAP",
            icon: "cryptocap"
        }, {
            label: "Binance",
            value: "binance",
            icon: "binance"
        }, {
            label: "MEXC",
            value: "mexc",
            icon: "mexc"
        }, {
            label: "KuCoin",
            value: "kucoin",
            icon: "kucoin"
        }, {
            label: "Coinbase",
            value: "coinbase",
            icon: "coinbase"
        }, {
            label: "OKX",
            value: "okx",
            icon: "okx"
        }, {
            label: "Kraken",
            value: "kraken",
            icon: "kraken"
        }, {
            label: "Bybit",
            value: "bybit",
            icon: "bybit"
        } ],
        get sub_type() {
            return createSubTypeGetter("crypto", DEFAULT_SUB_TYPES.crypto);
        }
    },
    dex: {
        exchange: {
            pancakeswap: {
                label: "PancakeSwap",
                value: "pancakeswap",
                icon: "pancakeswap"
            },
            pancakeswap3bsc: {
                label: "PancakeSwap v3 (BSC)",
                value: "pancakeswap3bsc",
                icon: "pancakeswap3"
            },
            pancakeswap3eth: {
                label: "PancakeSwap v3 (ETH)",
                value: "pancakeswap3eth",
                icon: "pancakeswap3"
            },
            uniswap: {
                label: "Uniswap",
                value: "uniswap",
                icon: "uniswap"
            },
            uniswap3bsc: {
                label: "Uniswap v3 (BSC)",
                value: "uniswap3bsc",
                icon: "uniswap3"
            },
            uniswap3eth: {
                label: "Uniswap v3 (ETH)",
                value: "uniswap3eth",
                icon: "uniswap3"
            },
            uniswap3base: {
                label: "Uniswap v3 (Base)",
                value: "uniswap3base",
                icon: "uniswap3"
            },
            uniswap3polygon: {
                label: "Uniswap v3 (Polygon)",
                value: "uniswap3polygon",
                icon: "uniswap3"
            },
            uniswap3arbitrum: {
                label: "Uniswap v3 (Arbitrum)",
                value: "uniswap3arbitrum",
                icon: "uniswap3"
            },
            raydium: {
                label: "Raydium",
                value: "raydium",
                icon: "raydium"
            },
            pulsex: {
                label: "PulseX",
                value: "pulsex",
                icon: "pulsex"
            },
            pulsex2: {
                label: "PulseX v2",
                value: "pulsex2",
                icon: "pulsex"
            },
            vvsfinance: {
                label: "VVS Finance",
                value: "vvsfinance",
                icon: "vvsfinance"
            },
            orca: {
                label: "Orca",
                value: "orca",
                icon: "orca"
            },
            traderjoe: {
                label: "Trader Joe",
                value: "traderjoe",
                icon: "traderjoe"
            },
            curve: {
                label: "Curve",
                value: "curve",
                icon: "curve"
            },
            shadow: {
                label: "Shadow",
                value: "shadow",
                icon: "shadow"
            }
        }
    },
    forex: {
        exchange: [ {
            label: "London Currency Banks",
            value: "FX",
            icon: "fx"
        }, {
            label: "Orion North America",
            value: "ONA",
            icon: "ona"
        }, {
            label: "FX Chicago Market",
            value: "FCM",
            icon: "fcm"
        }, {
            label: "Singapore Forex Office",
            value: "SFO",
            icon: "sfo"
        }, {
            label: "Institutional Forex Research",
            value: "IFR",
            icon: "ifr"
        } ],
        get sub_type() {
            return createSubTypeGetter("forex", DEFAULT_SUB_TYPES.forex);
        }
    },
    stock: {
        country: COUNTRIES,
        get sub_type() {
            return createSubTypeGetter("stock", DEFAULT_SUB_TYPES.stock);
        },
        sector: SECTORS
    },
    dr: {
        country: COUNTRIES,
        sector: SECTORS
    },
    indices: {
        country: COUNTRIES
    },
    fund: {
        country: COUNTRIES,
        sector: SECTORS,
        get sub_type() {
            return createSubTypeGetter("fund", DEFAULT_SUB_TYPES.fund);
        }
    },
    index: {
        get sub_type() {
            return createSubTypeGetter("fund", DEFAULT_SUB_TYPES.fund);
        }
    }
};

export { COUNTRIES, SECTORS, MARKET_DATA };

if (typeof window !== "undefined") {
    window.COUNTRIES = COUNTRIES;
    window.SECTORS = SECTORS;
    window.MARKET_DATA = MARKET_DATA;
}