const config = window.ChargePandaConfig?.constants || {};

// --- 1. Billing Types ---
export const BILLING_TYPES = config.BILLING_TYPES_KEYS || {
    BILLING_ONETIME: 1,
    BILLING_SUBSCRIPTION: 2
};

// --- 2. Billing Cycles ---
// Mixin UI-specific 'one-time' cycle which isn't in DB cycles table
const dbCycles = config.BILLING_CYCLES_KEYS || {
    BILLING_CYCLE_DAILY: 1,
    BILLING_CYCLE_WEEKLY: 2,
    BILLING_CYCLE_MONTHLY: 3,
    BILLING_CYCLE_QUARTERLY: 4,
    BILLING_CYCLE_SEMI_ANNUALLY: 5,
    BILLING_CYCLE_YEARLY: 6
};

export const BILLING_CYCLES = {
    ...dbCycles,
    ONE_TIME: 'one-time' // UI helper, not a DB ID
};

// --- 3. Trial Units ---
export const TRIAL_UNITS = config.TRIAL_UNITS_KEYS || {
    TRIAL_DURATION_DAYS: 1,
    TRIAL_DURATION_WEEKS: 2,
    TRIAL_DURATION_MONTHS: 3,
    TRIAL_DURATION_YEARS: 4
};

// --- 4. License Validity Types ---
export const LICENSE_VALIDITY = config.LICENSE_VALIDITY_KEYS || {
    LICENSE_VALIDITY_NO_EXPIRY: 1,
    LICENSE_VALIDITY_CUSTOM: 2
};

// --- 5. License Duration Units ---
export const DURATION_UNITS = config.DURATION_UNITS_KEYS || {
    LICENSE_VALIDITY_DAYS: 1,
    LICENSE_VALIDITY_WEEKS: 2,
    LICENSE_VALIDITY_MONTHS: 3,
    LICENSE_VALIDITY_YEARS: 4
};

// --- 6. Support Duration Units ---
export const SUPPORT_DURATION_UNITS = config.SUPPORT_DURATION_UNITS_KEYS || {
    SUPPORT_DURATION_DAYS: 1,
    SUPPORT_DURATION_WEEKS: 2,
    SUPPORT_DURATION_MONTHS: 3,
    SUPPORT_DURATION_YEARS: 4
};

// Helper to get Label
export const getConstantLabel = (type, value) => {
    if (config[type] && config[type][value]) return config[type][value];
    return value;
}
