/**
 * Blog Over Customizer Hero Widget Visibility
 * 
 * Hides widget repeater items based on slide count selection.
 * - Slide Count 1: Show only Slider 1 widget
 * - Slide Count 2: Show Slider 1 and 2 widgets
 * - Slide Count 3: Show all 3 widgets
 */
(function ($) {
    'use strict';

    wp.customize.bind('ready', function () {

        // Function to update widget visibility
        function updateWidgetVisibility(slideCount) {
            var count = parseInt(slideCount, 10) || 3;

            // Find the repeater control
            var repeaterControl = wp.customize.control('blog_over_hero_slider_widgets');
            if (!repeaterControl) return;

            var $container = repeaterControl.container;
            var $rows = $container.find('.repeater-row');

            $rows.each(function (index) {
                if (index < count) {
                    $(this).slideDown(200);
                } else {
                    $(this).slideUp(200);
                }
            });
        }

        // Initial visibility update
        var initialCount = wp.customize('blog_over_hero_slide_count').get();
        setTimeout(function () {
            updateWidgetVisibility(initialCount);
        }, 500);

        // Update on slide count change
        wp.customize('blog_over_hero_slide_count', function (setting) {
            setting.bind(function (newValue) {
                updateWidgetVisibility(newValue);
            });
        });
    });

})(jQuery);
