/**
 * 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 ( 'H1' === anchor.tagName ) {
		anchor = anchor.firstChild;
	}

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

	// Header text color.
	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;
			}
		} );
	} );

	//hide post date	
	  wp.customize('magazinestyle_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('magazinestyle_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( 'magazinestyle_site_info_override', function ( value ) {
		value.bind( function ( to ) {
			document.querySelector( '.site-info' ).innerHTML = to;
		} );
	} );

	

} )( jQuery );