$(document).ready(function() {
    let revenueLabels = ['<10M', '10M-50M', '50M-100M', '100M-500M', '500M-1B', '1B-5B', '5B-10B', '10B+'];

    $('#revenueTier').on('input', function() {
        let revenueIndex = parseInt($(this).val());
        $('#revenueTierLabel').text(revenueLabels[revenueIndex]);
    });

    $('#calculateButton').click(function() {
        let revenueTier = parseInt($('#revenueTier').val());
        let fiveSuppliers = $('#fiveSuppliers').is(':checked');
        let modules = [];
        $('input[type="checkbox"]:checked').each(function() {
            if ($(this).attr('id') !== 'fiveSuppliers') {
                modules.push($(this).val());
            }
        });

        let monthlyFees = [100, 250, 500, 1000, 2000, 3000, 3500, 4000]; // Monthly fees
        let setupFees = [2500, 5000, 10000, 20000, 30000, 35000, 40000, 45000]; // Setup fees
        let acceleratedLaunchCost = parseInt($('#acceleratedLaunch').val());
        let apiCustomizationCost = parseInt($('#apiCustomization').val());
        let multiYearDiscount = parseInt($('#multiYearContract').val());

        let totalMonthlyCost = 0;
        let totalSetupCost = 0;

        for (let i = 0; i < modules.length; i++) {
            totalMonthlyCost += monthlyFees[revenueTier];
            if (!fiveSuppliers) {
                totalSetupCost += setupFees[revenueTier];
            }
        }

        let totalCost = totalMonthlyCost + totalSetupCost + acceleratedLaunchCost + apiCustomizationCost - multiYearDiscount;
        $('#totalCost').text(totalCost);

        // Display Breakdown Table
        $('#monthlyCostValue').text(totalMonthlyCost);
        $('#setupCostValue').text(totalSetupCost);
        $('#acceleratedLaunchValue').text(acceleratedLaunchCost);
        $('#apiCustomizationValue').text(apiCustomizationCost);
        $('#multiYearDiscountValue').text(multiYearDiscount);

        $('#costBreakdown').show();
    });
});