function getFilterLang(key, fallback, params = null) {
    let result = getLang(key, fallback);
    if (params) {
        Object.keys(params).forEach(param => {
            result = result.replace(new RegExp(`\\{${param}\\}`, "g"), params[param]);
        });
    }
    return result;
}

function formatFilterNumber(num) {
    if (num === null || num === undefined) return "";
    const absNum = Math.abs(num);
    if (absNum >= 1e12) return (num / 1e12).toFixed(absNum % 1e12 === 0 ? 0 : 1) + "T";
    if (absNum >= 1e9) return (num / 1e9).toFixed(absNum % 1e9 === 0 ? 0 : 1) + "B";
    if (absNum >= 1e6) return (num / 1e6).toFixed(absNum % 1e6 === 0 ? 0 : 1) + "M";
    if (absNum >= 1e3) return num.toLocaleString("en-US");
    return num.toString();
}

function generateFilterLabel(item) {
    const {min: min, max: max, condition: condition, labelKey: labelKey} = item;
    if (labelKey) {
        return getFilterLang(`filters.labels.${labelKey}`, item.fallbackLabel || "", {
            value: formatFilterNumber(min ?? max),
            min: formatFilterNumber(min),
            max: formatFilterNumber(max)
        });
    }
    const minStr = formatFilterNumber(min);
    const maxStr = formatFilterNumber(max);
    switch (condition) {
      case "above":
        return getFilterLang("filters.templates.above_value", `Above ${minStr}`, {
            value: minStr
        });

      case "below":
        return getFilterLang("filters.templates.below_value", `Below ${maxStr}`, {
            value: maxStr
        });

      case "above-or-equal":
        return getFilterLang("filters.templates.value_or_above", `${minStr} or Above`, {
            value: minStr
        });

      case "below-or-equal":
        return getFilterLang("filters.templates.value_or_below", `${maxStr} or Below`, {
            value: maxStr
        });

      case "between":
        return getFilterLang("filters.templates.value_to_value", `${minStr} to ${maxStr}`, {
            min: minStr,
            max: maxStr
        });

      case "equal":
        return getFilterLang("filters.templates.equal_value", `Equal ${minStr}`, {
            value: minStr
        });

      default:
        return `${minStr} - ${maxStr}`;
    }
}

export function getDefaultFilters(type) {
    const defaultFilters = {
        "crypto": [ "price", "change-percent", "volume", "volume-24h", "weekly-perf", "exchange" ],
        "coin": [ "rank", "price", "volume", "weekly-perf", "signal-summary" ],
        "dex": [ "price", "change-percent", "volume", "volume-24h", "weekly-perf" ],
        "forex": [ "price", "open", "change-percent", "bid", "ask" ],
        "stock": [ "price", "change-percent", "volume", "country", "sector", "exchange" ],
        "dr": [ "price", "change-percent", "country", "sector", "signal-summary" ],
        "fund": [ "price", "change-percent", "country", "sector", "sub-type" ],
        "default": [ "price", "change-percent", "volume" ]
    };
    return defaultFilters[type] || defaultFilters.default;
}

export function getFilterConditions() {
    return {
        "above": {
            label: getFilterLang("filters.conditions.above", "Above"),
            operator: "_gt",
            inputs: "min",
            api_format: "single",
            svg_id: "chevron-right"
        },
        "below": {
            label: getFilterLang("filters.conditions.below", "Below"),
            operator: "_lt",
            inputs: "max",
            api_format: "single",
            svg_id: "chevron-left"
        },
        "between": {
            label: getFilterLang("filters.conditions.between", "Between"),
            operator: "_between",
            inputs: "both",
            api_format: "range",
            svg_id: "between"
        },
        "equal": {
            label: getFilterLang("filters.conditions.equal", "Equal to"),
            operator: "_eq",
            inputs: "value",
            api_format: "single",
            svg_id: "equal"
        },
        "above-or-equal": {
            label: getFilterLang("filters.conditions.above_or_equal", "Above or Equal"),
            operator: "_gte",
            inputs: "min",
            api_format: "single",
            svg_id: "greater-equal"
        },
        "below-or-equal": {
            label: getFilterLang("filters.conditions.below_or_equal", "Below or Equal"),
            operator: "_lte",
            inputs: "max",
            api_format: "single",
            svg_id: "less-equal"
        }
    };
}

export const FILTER_CONDITIONS = {
    "above": {
        label: "Above",
        operator: "_gt",
        inputs: "min",
        api_format: "single",
        svg_id: "chevron-right"
    },
    "below": {
        label: "Below",
        operator: "_lt",
        inputs: "max",
        api_format: "single",
        svg_id: "chevron-left"
    },
    "between": {
        label: "Between",
        operator: "_between",
        inputs: "both",
        api_format: "range",
        svg_id: "between"
    },
    "equal": {
        label: "Equal to",
        operator: "_eq",
        inputs: "value",
        api_format: "single",
        svg_id: "equal"
    },
    "above-or-equal": {
        label: "Above or Equal",
        operator: "_gte",
        inputs: "min",
        api_format: "single",
        svg_id: "greater-equal"
    },
    "below-or-equal": {
        label: "Below or Equal",
        operator: "_lte",
        inputs: "max",
        api_format: "single",
        svg_id: "less-equal"
    }
};

export function getDefaultConditionsForMetric(metricKey) {
    const METRIC_CONDITIONS = {
        "volume": [ "above", "below", "between" ],
        "volume-24h": [ "above", "below", "between" ],
        "change": [ "above", "below", "between", "equal" ],
        "change-percent": [ "above", "below", "between", "equal" ],
        "daily-perf": [ "above", "below", "between" ],
        "weekly-perf": [ "above", "below", "between" ],
        "monthly-perf": [ "above", "below", "between" ],
        "3-months-perf": [ "above", "below", "between" ],
        "yearly-perf": [ "above", "below", "between" ],
        "ytd-perf": [ "above", "below", "between" ],
        "market-cap": [ "above", "below", "between" ],
        "bid": [ "above", "below", "between" ],
        "ask": [ "above", "below", "between" ],
        "spread": [ "above", "below" ],
        "rsi": [ "above", "below", "between" ],
        "macd": [ "above", "below" ],
        "adx": [ "above", "below", "between" ],
        "atr": [ "above", "below", "between" ],
        "52w-high": [ "above", "below", "between" ],
        "52w-low": [ "above", "below", "between" ],
        "rank": [ "between" ]
    };
    return METRIC_CONDITIONS[metricKey] || [ "above", "below", "between", "equal", "above-or-equal", "below-or-equal" ];
}

export function getPredefinedValue(filterType, category) {
    const FILTER_DATA = {
        price: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: 100,
                max: 1e3,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            coin: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: 100,
                max: 1e3,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 500,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        open: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            coin: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 500,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: null,
                max: 100,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 100,
                condition: "below"
            } ]
        },
        close: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            coin: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 500,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: null,
                max: 100,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 100,
                condition: "below"
            } ]
        },
        high: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            coin: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 500,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: null,
                max: 100,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 100,
                condition: "below"
            } ]
        },
        low: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            coin: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 5e4,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 500,
                max: null,
                condition: "above-or-equal"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: null,
                max: 100,
                condition: "below-or-equal"
            }, {
                min: null,
                max: 100,
                condition: "below"
            } ]
        },
        change: {
            all: [ {
                min: 10,
                max: null,
                condition: "above"
            }, {
                min: 5,
                max: 10,
                condition: "between"
            }, {
                min: 0,
                max: 0,
                condition: "equal"
            }, {
                min: null,
                max: -5,
                condition: "below"
            } ]
        },
        "change-percent": {
            all: [ {
                min: 30,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: null,
                condition: "above"
            }, {
                min: 5,
                max: 10,
                condition: "between"
            }, {
                min: 0,
                max: 0,
                condition: "equal"
            }, {
                min: 0,
                max: 5,
                condition: "between"
            }, {
                min: null,
                max: -5,
                condition: "below"
            } ]
        },
        volume: {
            crypto: [ {
                min: 1e10,
                max: null,
                condition: "above"
            }, {
                min: 1e9,
                max: 1e10,
                condition: "between"
            }, {
                min: 1e8,
                max: 1e9,
                condition: "between"
            }, {
                min: 1e7,
                max: 1e8,
                condition: "between"
            }, {
                min: null,
                max: 1e7,
                condition: "below"
            } ],
            coin: [ {
                min: 1e10,
                max: null,
                condition: "above"
            }, {
                min: 1e9,
                max: 1e10,
                condition: "between"
            }, {
                min: 1e8,
                max: 1e9,
                condition: "between"
            }, {
                min: 1e7,
                max: 1e8,
                condition: "between"
            }, {
                min: null,
                max: 1e7,
                condition: "below"
            } ],
            forex: [ {
                min: 1e9,
                max: null,
                condition: "above"
            }, {
                min: 1e8,
                max: 1e9,
                condition: "between"
            }, {
                min: 1e7,
                max: 1e8,
                condition: "between"
            }, {
                min: 1e6,
                max: 1e7,
                condition: "between"
            }, {
                min: null,
                max: 1e6,
                condition: "below"
            } ],
            stock: [ {
                min: 5e8,
                max: null,
                condition: "above"
            }, {
                min: 1e8,
                max: 5e8,
                condition: "between"
            }, {
                min: 1e7,
                max: 1e8,
                condition: "between"
            }, {
                min: 1e6,
                max: 1e7,
                condition: "between"
            }, {
                min: null,
                max: 1e6,
                condition: "below"
            } ]
        },
        "volume-24h": {
            crypto: [ {
                min: 1e10,
                max: null,
                condition: "above"
            }, {
                min: 1e9,
                max: 1e10,
                condition: "between"
            }, {
                min: 1e8,
                max: 1e9,
                condition: "between"
            }, {
                min: 1e7,
                max: 1e8,
                condition: "between"
            }, {
                min: null,
                max: 1e7,
                condition: "below"
            } ]
        },
        "market-cap": {
            crypto: [ {
                min: 1e11,
                max: null,
                condition: "above"
            }, {
                min: 1e10,
                max: 1e11,
                condition: "between"
            }, {
                min: 1e9,
                max: 1e10,
                condition: "between"
            }, {
                min: 1e8,
                max: 1e9,
                condition: "between"
            }, {
                min: null,
                max: 1e8,
                condition: "below"
            } ],
            stock: [ {
                min: 2e11,
                max: null,
                condition: "above",
                labelKey: "mega_cap",
                fallbackLabel: "Above 200B (Mega)"
            }, {
                min: 1e10,
                max: 2e11,
                condition: "between",
                labelKey: "large_cap",
                fallbackLabel: "10B to 200B (Large)"
            }, {
                min: 2e9,
                max: 1e10,
                condition: "between",
                labelKey: "mid_cap",
                fallbackLabel: "2B to 10B (Mid)"
            }, {
                min: 3e8,
                max: 2e9,
                condition: "between",
                labelKey: "small_cap",
                fallbackLabel: "300M to 2B (Small)"
            }, {
                min: null,
                max: 3e8,
                condition: "below",
                labelKey: "micro_cap",
                fallbackLabel: "Below 300M (Micro)"
            } ]
        },
        "daily-perf": {
            all: [ {
                min: 10,
                max: null,
                condition: "above",
                labelKey: "up_percent",
                fallbackLabel: "Up 10%+"
            }, {
                min: 5,
                max: 10,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 5% to 10%"
            }, {
                min: 0,
                max: 5,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 0% to 5%"
            }, {
                min: -5,
                max: 0,
                condition: "between",
                labelKey: "down_range_percent",
                fallbackLabel: "Down 0% to 5%"
            }, {
                min: null,
                max: -5,
                condition: "below",
                labelKey: "down_percent",
                fallbackLabel: "Down 5%+"
            } ]
        },
        "weekly-perf": {
            all: [ {
                min: 20,
                max: null,
                condition: "above",
                labelKey: "up_percent",
                fallbackLabel: "Up 20%+"
            }, {
                min: 10,
                max: 20,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 10% to 20%"
            }, {
                min: 0,
                max: 10,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 0% to 10%"
            }, {
                min: -10,
                max: 0,
                condition: "between",
                labelKey: "down_range_percent",
                fallbackLabel: "Down 0% to 10%"
            }, {
                min: null,
                max: -10,
                condition: "below",
                labelKey: "down_percent",
                fallbackLabel: "Down 10%+"
            } ]
        },
        "monthly-perf": {
            all: [ {
                min: 50,
                max: null,
                condition: "above",
                labelKey: "up_percent",
                fallbackLabel: "Up 50%+"
            }, {
                min: 20,
                max: 50,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 20% to 50%"
            }, {
                min: 0,
                max: 20,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 0% to 20%"
            }, {
                min: -20,
                max: 0,
                condition: "between",
                labelKey: "down_range_percent",
                fallbackLabel: "Down 0% to 20%"
            }, {
                min: null,
                max: -20,
                condition: "below",
                labelKey: "down_percent",
                fallbackLabel: "Down 20%+"
            } ]
        },
        bid: {
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ]
        },
        ask: {
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ]
        },
        spread: {
            all: [ {
                min: .1,
                max: null,
                condition: "above",
                labelKey: "wide_spread",
                fallbackLabel: "Wide (Above 0.1)"
            }, {
                min: null,
                max: .1,
                condition: "below",
                labelKey: "tight_spread",
                fallbackLabel: "Tight (Below 0.1)"
            } ]
        },
        rsi: {
            all: [ {
                min: 70,
                max: null,
                condition: "above",
                labelKey: "overbought",
                fallbackLabel: "Overbought (70+)"
            }, {
                min: 50,
                max: 70,
                condition: "between",
                labelKey: "neutral_range",
                fallbackLabel: "Neutral (50-70)"
            }, {
                min: 30,
                max: 50,
                condition: "between",
                labelKey: "neutral_range",
                fallbackLabel: "Neutral (30-50)"
            }, {
                min: null,
                max: 30,
                condition: "below",
                labelKey: "oversold",
                fallbackLabel: "Oversold (Below 30)"
            } ]
        },
        ema10: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            coin: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        ema25: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            coin: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        ema50: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        ema100: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        ema200: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        sma10: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        sma25: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        sma50: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        sma100: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        sma200: {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: 1,
                max: 10,
                condition: "between"
            }, {
                min: null,
                max: 1,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ]
        },
        macd: {
            all: [ {
                min: 0,
                max: null,
                condition: "above",
                labelKey: "bullish_above",
                fallbackLabel: "Bullish (Above 0)"
            }, {
                min: null,
                max: 0,
                condition: "below",
                labelKey: "bearish_below",
                fallbackLabel: "Bearish (Below 0)"
            } ]
        },
        adx: {
            all: [ {
                min: 50,
                max: null,
                condition: "above",
                labelKey: "very_strong_trend",
                fallbackLabel: "Very Strong Trend (50+)"
            }, {
                min: 25,
                max: 50,
                condition: "between",
                labelKey: "strong_trend",
                fallbackLabel: "Strong Trend (25-50)"
            }, {
                min: null,
                max: 25,
                condition: "below",
                labelKey: "weak_trend",
                fallbackLabel: "Weak Trend (Below 25)"
            } ]
        },
        atr: {
            all: [ {
                min: 3,
                max: null,
                condition: "above",
                labelKey: "high_volatility",
                fallbackLabel: "High Volatility (Above 3)"
            }, {
                min: 1,
                max: 3,
                condition: "between",
                labelKey: "medium_volatility",
                fallbackLabel: "Medium Volatility (1-3)"
            }, {
                min: null,
                max: 1,
                condition: "below",
                labelKey: "low_volatility",
                fallbackLabel: "Low Volatility (Below 1)"
            } ]
        },
        "52w-high": {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: null,
                max: 100,
                condition: "below"
            } ]
        },
        "52w-low": {
            crypto: [ {
                min: 5e4,
                max: null,
                condition: "above"
            }, {
                min: 1e4,
                max: 5e4,
                condition: "between"
            }, {
                min: 1e3,
                max: 1e4,
                condition: "between"
            }, {
                min: null,
                max: 1e3,
                condition: "below"
            } ],
            forex: [ {
                min: 100,
                max: null,
                condition: "above"
            }, {
                min: 10,
                max: 100,
                condition: "between"
            }, {
                min: null,
                max: 10,
                condition: "below"
            } ],
            stock: [ {
                min: 500,
                max: null,
                condition: "above"
            }, {
                min: 100,
                max: 500,
                condition: "between"
            }, {
                min: null,
                max: 100,
                condition: "below"
            } ]
        },
        "3-months-perf": {
            all: [ {
                min: 100,
                max: null,
                condition: "above",
                labelKey: "up_percent",
                fallbackLabel: "Up 100%+"
            }, {
                min: 50,
                max: 100,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 50% to 100%"
            }, {
                min: 20,
                max: 50,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 20% to 50%"
            }, {
                min: 0,
                max: 20,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 0% to 20%"
            }, {
                min: -20,
                max: 0,
                condition: "between",
                labelKey: "down_range_percent",
                fallbackLabel: "Down 0% to 20%"
            }, {
                min: null,
                max: -20,
                condition: "below",
                labelKey: "down_percent",
                fallbackLabel: "Down 20%+"
            } ]
        },
        "yearly-perf": {
            all: [ {
                min: 200,
                max: null,
                condition: "above",
                labelKey: "up_percent",
                fallbackLabel: "Up 200%+"
            }, {
                min: 100,
                max: 200,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 100% to 200%"
            }, {
                min: 50,
                max: 100,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 50% to 100%"
            }, {
                min: 0,
                max: 50,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 0% to 50%"
            }, {
                min: -50,
                max: 0,
                condition: "between",
                labelKey: "down_range_percent",
                fallbackLabel: "Down 0% to 50%"
            }, {
                min: null,
                max: -50,
                condition: "below",
                labelKey: "down_percent",
                fallbackLabel: "Down 50%+"
            } ]
        },
        "ytd-perf": {
            all: [ {
                min: 100,
                max: null,
                condition: "above",
                labelKey: "up_percent",
                fallbackLabel: "Up 100%+"
            }, {
                min: 50,
                max: 100,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 50% to 100%"
            }, {
                min: 20,
                max: 50,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 20% to 50%"
            }, {
                min: 0,
                max: 20,
                condition: "between",
                labelKey: "up_range_percent",
                fallbackLabel: "Up 0% to 20%"
            }, {
                min: -20,
                max: 0,
                condition: "between",
                labelKey: "down_range_percent",
                fallbackLabel: "Down 0% to 20%"
            }, {
                min: null,
                max: -20,
                condition: "below",
                labelKey: "down_percent",
                fallbackLabel: "Down 20%+"
            } ]
        },
        "rank": {
            coin: [ {
                min: null,
                max: 10,
                condition: "below-or-equal",
                labelKey: "top_value",
                fallbackLabel: "Top 10"
            }, {
                min: null,
                max: 50,
                condition: "below-or-equal",
                labelKey: "top_value",
                fallbackLabel: "Top 50"
            }, {
                min: null,
                max: 100,
                condition: "below-or-equal",
                labelKey: "top_value",
                fallbackLabel: "Top 100"
            }, {
                min: null,
                max: 150,
                condition: "below-or-equal",
                labelKey: "top_value",
                fallbackLabel: "Top 150"
            }, {
                min: null,
                max: 200,
                condition: "below-or-equal",
                labelKey: "top_value",
                fallbackLabel: "Top 200"
            }, {
                min: null,
                max: 500,
                condition: "below-or-equal",
                labelKey: "top_value",
                fallbackLabel: "Top 500"
            } ]
        }
    };
    if (!FILTER_DATA[filterType]) return null;
    const data = FILTER_DATA[filterType][category] || FILTER_DATA[filterType]["all"] || null;
    if (data && Array.isArray(data)) {
        return data.map(item => ({
            ...item,
            label: generateFilterLabel(item)
        }));
    }
    return data;
}