/**
 * File: customizer.js.
 *
 * Theme Customizer enhancements for a better user experience.
 *
 * Contains handlers to make Theme Customizer preview reload changes asynchronously.
 */

 ( function () {
	 
	 let anchor = document.querySelector( '.navbar-brand a' );
    
    if (anchor && anchor.tagName === 'H1') {
        anchor = anchor.firstChild;
    }

    // If the anchor exists, handle the header text color customization.
    if (anchor) {
        wp.customize( 'header_textcolor', function ( value ) {
            value.bind( function ( to ) {
                if ( 'blank' === to ) {
                    anchor.style.clip = 'rect(1px, 1px, 1px, 1px)';
                    anchor.style.position = 'absolute';
                } else {
                    anchor.style.clip = 'auto';
                    anchor.style.position = 'relative';
                    anchor.style.color = to;
                }
            } );
        } );
    } else {
        console.warn('Anchor element with .navbar-brand a not found.');
    }

	// Site title.
	wp.customize( 'blogname', function ( value ) {
		value.bind( function ( to ) {
			anchor.textContent = to;
		} );
	} );



	//hide post date	
	  wp.customize('digital_single_meta', function (value) {
    value.bind(function (newVal) {
      if (newVal === 'disable') {
        $('.post-date').hide(); // Replace '.post-date' with the CSS class or selector that represents your post date element
      } else {
        $('.post-date').show();
      }
    });
  });

 wp.customize('digital_heroarea', function (value) {
        value.bind(function (newVal) {
            if ('enable' === newVal) {
                $('.styletwo-header #wrapper-hero').css('margin-top', '-76px');
            } else {
                // Reset to default or any other value
                $('.styletwo-header #wrapper-hero').css('margin-top', '0');
            }

            // Trigger an instant refresh
            wp.customize.previewer.refresh();
        });
    });
	// Site info.
	wp.customize( 'digital_site_info_override', function ( value ) {
		value.bind( function ( to ) {
			document.querySelector( '.site-info' ).innerHTML = to;
		} );
	} );

	

} )( jQuery );