/**
 * Blog Over Alpha Color Picker
 * 
 * Initializes color pickers with alpha support
 *
 * @package Blog_Over
 */

(function($) {
    'use strict';

    /**
     * Initialize alpha color pickers
     */
    function initAlphaColorPicker() {
        $('.blog-over-alpha-color-input').each(function() {
            var $input = $(this);
            
            if ($input.data('blog-over-color-init')) {
                return;
            }
            
            $input.wpColorPicker({
                change: function(event, ui) {
                    var color = ui.color.toString();
                    $input.val(color).trigger('change');
                },
                clear: function() {
                    $input.val('').trigger('change');
                }
            });
            
            $input.data('blog-over-color-init', true);
        });
    }

    // Initialize on DOM ready
    $(document).ready(function() {
        initAlphaColorPicker();
    });

    // Re-initialize when Customizer panels are loaded
    if (typeof wp !== 'undefined' && typeof wp.customize !== 'undefined') {
        wp.customize.bind('ready', function() {
            initAlphaColorPicker();
        });

        wp.customize.control.bind('add', function() {
            setTimeout(initAlphaColorPicker, 100);
        });
    }

})(jQuery);
