jQuery(document).ready(function($) {
    // Function to toggle the specific container based on the selected type
    function toggleSpecificContainer() {
        var selectedType = $('input[name="pchfw_rule[select_type]"]:checked').val();

        // Show/hide Include and Exclude Products sections based on the selected type
        $('.filter-section').hide();
        $('.filter-section[data-filter-type="' + selectedType + '"]').show();

        var selectedvalue = $("input[name='pchfw_rule[include_"+ selectedType +"][toggle]']:checked").val();

        if (selectedvalue === 'all') {
            $('label[for=wc_rule_data_'+ selectedType +'_specific] div.rules-specific-container').slideUp();
            $('.exclude-filter[data-filter-type="' + selectedType + '"]').show();
        } else {
            $('label[for=wc_rule_data_'+ selectedType +'_specific] div.rules-specific-container').slideDown();
            $('.exclude-filter[data-filter-type="' + selectedType + '"]').hide();
        }

    }

    toggleSpecificContainer();

    // Handle change event of the type radio buttons
    $('input[name="pchfw_rule[select_type]"]').on('change', function() {
        toggleSpecificContainer();
    });
    
    $("input[name='pchfw_rule[include_category][toggle]']").on('change', function() {
        var selected = $(this).val();
        //toggleContainer("wc_rule_data_category_specific", selected);
        toggleSpecificContainer();
    });

    $("input[name='pchfw_rule[include_product][toggle]']").on('change', function() {
        var selected = $(this).val();
        //toggleContainer("wc_rule_data_prod_specific", selected);
        toggleSpecificContainer();
    });

    $("input[name='pchfw_rule[include_tag][toggle]']").on('change', function() {
        var selected = $(this).val();
        //toggleContainer("wc_rule_data_tag_specific", selected);
        toggleSpecificContainer();
    });
});
