/**
 * File customizer.js.
 *
 * Theme Customizer enhancements for a better user experience.
 *
 * Contains handlers to make Theme Customizer preview reload changes asynchronously.
 */
( function( $ ) {
	// Site title and description.
	wp.customize( 'blogname', function( value ) {
		value.bind( function( to ) {
			$( '.site-title a' ).text( to );
		} );
	} );
	wp.customize( 'blogdescription', function( value ) {
		value.bind( function( to ) {
			$( '.site-description' ).text( to );
		} );
	} );
	wp.customize( 'background_color', function( value ) {
		value.bind( function( to ) {
			if ('#ffffff' === to) {
				$('body.home').removeClass('custom-background');
			}else{
				$('body.home').addClass('custom-background');
			}
		} );
	} );
	wp.customize( 'background_image', function( value ) {
		value.bind( function( to ) {
			if ('' === to || null === to || 'undefined' === to) {
				$('body.home').removeClass('custom-background');
			}else{
				$('body.home').addClass('custom-background');
			}
		} );
	} );
	// Header text color.
	wp.customize( 'header_textcolor', function( value ) {
		value.bind( function( to ) {
			if ( 'blank' === to ) {
				$( '.site-title, .site-description' ).css( {
					'clip': 'rect(1px, 1px, 1px, 1px)',
					'position': 'absolute'
				} );
			} else {
				$( '.site-title, .site-description' ).css( {
					'clip': 'auto',
					'position': 'relative'
				} );
				$( '.site-title a, .site-description' ).css( {
					'color': to
				} );
			}
		} );
	} );

// আপনার customizer.js ফাইলের একদম নিচে এই কোডটুকু রাখুন

jQuery(document).ready(function($) {
    
    $('body').on('click', '.customizer-edit-section-icon', function(e) {
        e.preventDefault();
        
        var sectionId = $(this).data('section'); 
        console.log("১. Icon Clicked! Trying to open section:", sectionId);
        
        // Iframe থেকে সরাসরি Parent Window-এর wp.customize অ্যাক্সেস করা
        if ( sectionId && window.parent && window.parent.wp && window.parent.wp.customize ) {
            
            var targetSection = window.parent.wp.customize.section( sectionId );
            
            if ( targetSection ) {
                // সেকশনটি খুঁজে পেলে সরাসরি ওপেন করে দেবে
                targetSection.expand(); 
                console.log("২. Success! Section opened directly.");
            } else {
                console.log("❌ Error: Section ID '" + sectionId + "' not found in Customizer!");
            }
            
        } else {
            console.log("❌ Error: Cannot access parent window Customizer.");
        }
    });

});    
} )( jQuery );
