<?php
/**
 * Wrock Metro Theme Customizer
 *
 * @package Wrock Metro
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'wrockmetro_customize_register' ) ) {
	
	
	
	/**
	 * Register basic support (site title, header text color) for the Theme Customizer.
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer reference.
	 */
	function wrockmetro_customize_register( $wp_customize ) {
		$settings = array( 'blogname', 'header_textcolor' );
		foreach ( $settings as $setting ) {
			$get_setting = $wp_customize->get_setting( $setting );
			if ( $get_setting instanceof WP_Customize_Setting ) {
				$get_setting->transport = 'postMessage';
			}
		}

		// Override default partial for custom logo.
		$wp_customize->selective_refresh->add_partial(
			'custom_logo',
			array(
				'settings'            => array( 'custom_logo' ),
				'selector'            => '.custom-logo-link',
				'render_callback'     => 'wrockmetro_customize_partial_custom_logo',
				'container_inclusive' => false,
			)
		);
		
		class wrockmetro_Important_Links extends WP_Customize_Control {

      public $type = "wrockmetro-important-links";

      public function render_content() {
      
		 echo '<ul><b>
			<li>' . esc_attr__( '* Fully Mobile Responsive', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Dedicated Option Panel', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Customize Theme Color', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* WooCommerce & bbPress Support', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* SEO Optimized', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Control Individual Meta Option like: Category, date, Author, Tags etc. ', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Full Support', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Google Fonts', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Theme Color Customization', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Custom CSS', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Website Layout', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Select Number of Columns', 'wrock-metro' ) . '</li>
			<li>' . esc_attr__( '* Website Width Control', 'wrock-metro' ) . '</li>
			</b></ul>
		 ';
         $important_links = array(
		 
            'theme-info' => array(
               'link' => esc_url('https://www.insertcart.com/product/wrockmetro-pro-wordpress-theme/'),
               'text' => __('Wrock Metro Pro', 'wrock-metro'),
            ),
            'support' => array(
               'link' => esc_url('https://www.insertcart.com/contact-us/'),
               'text' => __('Contact us', 'wrock-metro'),
            ),         
			'Documentation' => array(
               'link' => esc_url('https://www.insertcart.com/wrockmetro-theme-setup-guide/'),
               'text' => __('Documentation', 'wrock-metro'),
            ),			 
         );
         foreach ($important_links as $important_link) {
            echo '<p><a target="_blank" href="' . $important_link['link'] . '" >' . esc_attr($important_link['text']) . ' </a></p>';
         }
               }

   }
      $wp_customize->add_section('wrockmetro_important_links', array(
      'priority' => 1,
      'title' => __('Upgrade to Pro', 'wrock-metro'),
	   ));

	   $wp_customize->add_setting('wrockmetro_important_links', array(
		  'capability' => 'edit_theme_options',
		  'sanitize_callback' => 'wrockmetro_links_sanitize'
	   ));

	   $wp_customize->add_control(new wrockmetro_Important_Links($wp_customize, 'important_links', array(
		  'section' => 'wrockmetro_important_links',
		  'settings' => 'wrockmetro_important_links'
	   )));	 
	}
}
add_action( 'customize_register', 'wrockmetro_customize_register' );


if ( ! function_exists( 'wrockmetro_customize_partial_custom_logo' ) ) {
	/**
	 * Callback for rendering the custom logo, used in the custom_logo partial.
	 *
	 * @return string The custom logo markup or the site title.
	 */
	function wrockmetro_customize_partial_custom_logo() {
		if ( has_custom_logo() ) {
			return get_custom_logo();
		} else {
			return get_bloginfo( 'name' );
		}
	}
}


//$dir = wrockmetro_INC_DIR . 'customizer/controls/';

if ( ! function_exists( 'wrockmetro_theme_customize_register' ) ) {
	
	function wrockmetro_theme_customize_register( $wp_customize ) {


		class wrockmetro_Customizer_Buttonset_Control extends \WP_Customize_Control {
			//public $type = 'text_radio_button';
			
			public function render_content() {
				?>
				<div class="text_radio_button_control">
				<?php if ( ! empty( $this->label ) ) { ?>
					<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
				<?php } ?>
				<?php if ( ! empty( $this->description ) ) { ?>
					<span class="customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span>
				<?php } ?>				
					<div class="radio-buttons">
						<?php foreach ( $this->choices as $key => $value ) { ?>
							<label class="radio-button-label">
								<input type="radio" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php $this->link(); checked( $this->value(), $key ); ?>/>
								<span><?php echo esc_html( $value ); ?></span>
							</label>
						<?php	} ?>
					</div>
				</div>
				<?php
			}
		}
	

class wrockmetro_Image_Radio_Control extends \WP_Customize_Control {
    public function render_content() {
        if (empty($this->choices))
            return;

        $name = '_customize-radio-' . $this->id;
        ?>
        <span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
        <ul class="controls" id='wrockmetro-img-container'>
            <?php
            foreach ($this->choices as $value => $label) :
                $class = ($this->value() == $value) ? 'wrockmetro-radio-img-selected wrockmetro-radio-img-img' : 'wrockmetro-radio-img-img';
                ?>
                <li style="display: inline;">
                    <label>
                        <input <?php $this->link(); ?>style = 'display:none' type="radio" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($name); ?>" <?php
                                                      $this->link();
                                                      checked($this->value(), $value);
                                                      ?> />
                        <img src='<?php echo esc_url($label); ?>' class='wrockmetro-radio-img wrockmetro-radio-img-<?php echo esc_attr($value); ?>' alt="Select Style"/>
                    </label>
                </li>
                <?php
            endforeach;
            ?>
        </ul>
		<script>
            (function ($) {
				
                wp.customize.control('wrockmetro_posts_layout', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'wrockmetro-radio-img-selected' class from all images
                        $('ul#wrockmetro-img-container img').removeClass('wrockmetro-radio-img-selected');
                        // Add the 'wrockmetro-radio-img-selected' class to the selected image
                        $('ul#wrockmetro-img-container img.wrockmetro-radio-img-' + value).addClass('wrockmetro-radio-img-selected');
                    });
                });
                wp.customize.control('wrockmetro_sidebar_position', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'wrockmetro-radio-img-selected' class from all images
                        $('ul#wrockmetro-img-container img').removeClass('wrockmetro-radio-img-selected');
                        // Add the 'wrockmetro-radio-img-selected' class to the selected image
                        $('ul#wrockmetro-img-container img.wrockmetro-radio-img-' + value).addClass('wrockmetro-radio-img-selected');
                    });
                });
                wp.customize.control('wrockmetro_container_type', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'wrockmetro-radio-img-selected' class from all images
                        $('ul#wrockmetro-img-container img').removeClass('wrockmetro-radio-img-selected');
                        // Add the 'wrockmetro-radio-img-selected' class to the selected image
                        $('ul#wrockmetro-img-container img.wrockmetro-radio-img-' + value).addClass('wrockmetro-radio-img-selected');
                    });
                });
				  wp.customize.control('wrockmetro_posts_layout', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'wrockmetro-radio-img-selected' class from all images
                        $('ul#wrockmetro-img-container img').removeClass('wrockmetro-radio-img-selected');
                        // Add the 'wrockmetro-radio-img-selected' class to the selected image
                        $('ul#wrockmetro-img-container img.wrockmetro-radio-img-' + value).addClass('wrockmetro-radio-img-selected');
                    });
                });
                wp.customize.control('wrockmetro_header_style', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'wrockmetro-radio-img-selected' class from all images
                        $('ul#wrockmetro-img-container img').removeClass('wrockmetro-radio-img-selected');
                        // Add the 'wrockmetro-radio-img-selected' class to the selected image
                        $('ul#wrockmetro-img-container img.wrockmetro-radio-img-' + value).addClass('wrockmetro-radio-img-selected');
                    });
                });
				
				
            })(jQuery);
        </script>
			<?php
		}
	}
		
	if ( class_exists( 'WP_Customize_Panel' ) ):
	$wp_customize->register_control_type('wrockmetro_Customizer_Heading_Control');
	
	$wrockmetro_inc_dir = 'inc';
	$wrockmetro_includes_controls = array(
		'/controls/class-control-heading.php',               // Heading Controls.
		'/controls/woocommerce.php',                         // WooCommerce Controls.
		'/controls/footerarea.php',                          // Footer Controls.
		'/controls/headercontrol.php',                       // Header Control.
		'/controls/authorcontrol.php',                       // Author Control.
		'/controls/themeelement.php',                        // Theme element Control.
		'/controls/list-block-posts.php',                    // List block posts Control.
		'/controls/news-ticker.php',                         // News Ticker Control.
		'/controls/block-tiles.php',                         // Block Control.
		'/controls/post-settings.php',                         // Block Control.
		'/controls/post-singles.php',                         // Block Control.
		'/controls/sidebars.php',                         // sidebar
		'/controls/breadcrumbs.php',                         // Breadcrumbs
		'/controls/404errorcontrol.php',                         // 404 error
		'/controls/navigations.php',                         // 404 error
		'/controls/postnavi.php',                         // post navi
	);
	// Include files.
	foreach ( $wrockmetro_includes_controls as $file ) {
		require_once get_theme_file_path( $wrockmetro_inc_dir . $file );
	}
	
	$wp_customize->get_section( 'background_image' )->panel = 'panel_general';
	 $wp_customize->get_section( 'colors' )->panel = 'panel_general';
	
	$colors_section = $wp_customize->get_section( 'colors' );


	// Add "display_title_and_tagline" setting for displaying the site-title & tagline.
	$wp_customize->add_setting(
		'display_title_and_tagline',
		array(
			'capability'        => 'edit_theme_options',
			'default'           => true,
			'sanitize_callback' => 'wrockmetro_customize_sanitize_checkbox',
		)
	);

	// Add control for the "display_title_and_tagline" setting.
	$wp_customize->add_control(
		'display_title_and_tagline',
		array(
			'type'    => 'checkbox',
			'section' => 'title_tagline',
			'label'   => esc_html__( 'Display Site Title & Tagline', 'wrock-metro' ),
		)
	);

	$wp_customize->add_setting(
		'display_title_and_tagline',
		array(
			'capability'        => 'edit_theme_options',
			'default'           => true,
			'sanitize_callback' => 'wrockmetro_customize_sanitize_checkbox',
		)
	);


	/*********************
    Schema Markup
    *******************/
	$wp_customize->add_section('wrockmetro_schema_markup',
    array(
        'title'       => __( 'Schema', 'wrock-metro' ),
        'capability'  => 'edit_theme_options',						
        'panel'			=> 'panel_general',
        'priority'    => apply_filters( 'wrockmetro_postnavi_section_priority', 10 ),
    ));
$wp_customize->add_setting(
    'wrockmetro_enable_schema',
    array(
        'capability'        => 'edit_theme_options',
        'default'           => false,
        'sanitize_callback' => 'wrockmetro_customize_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'wrockmetro_enable_schema',
    array(
        'type'    => 'checkbox',
        'section' => 'wrockmetro_schema_markup',
        'label'   => esc_html__( 'Enable Schema', 'wrock-metro' ),
    )
);


    // Check if the section exists
    if ( $colors_section ) {
        // Set a new title for the colors section
        $colors_section->title = __( 'Theme Background Color', 'wrock-metro' );
    }
	$wp_customize->add_panel( 'panel_general', array(
			'priority' => 30,
			'capability' => 'edit_theme_options',
			'description' => __( 'Control theme default settings', 'wrock-metro' ),
			'priority'    => apply_filters( 'wrockmetro_theme_settings_priority', 150 ),
			'title' => __( 'Theme Settings', 'wrock-metro' )
		) );
	/*********************
	Browser Color
	*******************/
	$wp_customize->add_setting(
		'wrockmetro_browser_color', array(
		'default' => '#03A9F4', // Default font color
		'sanitize_callback' => 'sanitize_hex_color',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'wrockmetro_browser_color', array(
		'label' => __('Default Browser Color (Effect only Mobile)', 'wrock-metro'),
		'section' => 'colors',
		'settings' => 'wrockmetro_browser_color',
	)));		
		
		$wp_customize->add_section('custom_section_css',
				array(
					'title'			=> __( 'Custom CSS', 'wrock-metro' ),			
					'panel'			=> 'panel_general',
					'priority'    => 32
				)
			);
        $wp_customize->add_setting('custom_css',
		array(
			'default'			=> '',
			'type'				=> 'theme_mod',
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'    => 'wp_filter_nohtml_kses',
			'sanitize_js_callback' => 'wp_filter_nohtml_kses'
		)
	);
       $wp_customize->add_control('custom_css',
		array(

			'settings'		=> 'custom_css',
			'section'		=> 'custom_section_css',
			'type'			=> 'textarea',
			'label'			=> __( 'Custom CSS', 'wrock-metro' ),
			'description'	=> __( 'Define custom CSS be used for your site. Do not enclose in script tags.', 'wrock-metro' ),
		)
	);
	
		/*********************
		Menu settings. Style One
		*******************/
		$wp_customize->add_section(
			'wrockmetro_menu_settings',
			array(
				'title'       => __( 'Menu Settings', 'wrock-metro' ),
				'description'       => __( 'Menu Settings', 'wrock-metro' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'panel_general',
			)
		);
		
		$wp_customize->add_setting('wrockmetro_topside',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'wrockmetro_customize_sanitize_select'
			));
		$wp_customize->add_control('wrockmetro_topside',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Woocommerce/Search Bar in Right','wrock-metro'),
				'settings'   => 'wrockmetro_topside',
				'section' => 'wrockmetro_theme_settings',
				'choices' => array(
					'enable' => __('Enable','wrock-metro'),
					'disable' => __('Disable','wrock-metro'),
				 ),
			 ));		

		
		/*********************
		Social Links
		*******************/
		$wp_customize->add_section('wrockmetro_sociallinks',
			array(
				'title'       => __( 'Social Links', 'wrock-metro' ),
				'description'       => __( 'Author Profile Control on Posts and Archive Pages (Make Sure to fill all detail to show profile in Dashboard > Users > Profile)', 'wrock-metro' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'wrockmetro_theme_elements',
			));
			
		// Add setting for social media links style
    $wp_customize->add_setting('social_links_style', array(
        'default' => 'rounded-circle',
        'sanitize_callback' => 'sanitize_text_field',
    ));

    // Add control for social media links style
    $wp_customize->add_control('social_links_style', array(
        'label' => __('Social Links Style', 'wrock-metro'),
        'section' => 'wrockmetro_sociallinks',
        'type' => 'select',
        'choices' => array(
            'rounded' => __('Round', 'wrock-metro'),
            'rounded-circle' => __('Circle', 'wrock-metro'),
            'rounded-0' => __('Tile', 'wrock-metro'),
        ),
    ));	
	$social_media_platforms = array(
        'facebook' => __('Facebook', 'wrock-metro'),
        'twitter' => __('Twitter', 'wrock-metro'),
        'whatsapp' => __('WhatsApp', 'wrock-metro'),
        'calling' => __('Calling', 'wrock-metro'),
        'youtube' => __('YouTube', 'wrock-metro'),
		'telegram' => __('Telegram', 'republicpro'),
    );

    foreach ($social_media_platforms as $platform => $label) {
        $wp_customize->add_setting("social_media_$platform", array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
        ));

        $wp_customize->add_control("social_media_$platform", array(
            'label' => $label . ' URL',
            'section' => 'wrockmetro_sociallinks',
            'type' => 'text',
        ));
    }
		
		/*********************
		Google Fonts
		*******************/
		$wp_customize->add_section('wrockmetro_google_font',
			array(
				'title'       => __( 'Google Fonts', 'wrock-metro' ),
				'description'       => __( 'Google Fonts Settings', 'wrock-metro' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'panel_general',
			)
		);
		$font_array = array('Raleway','Khula','Open Sans','Poppins','Futura','Indie Flower','Droid Sans','Droid Serif','Roboto','Roboto Condensed','Lato','Bree Serif','Oswald','Slabo','Lora','Source Sans Pro','PT Sans','Ubuntu','Lobster','Arimo','Bitter','Noto Sans','Fjalla One','PT Sans Narrow','Poiret One','Passion One','Arvo','Inconsolata','Shadows Into Light','Pacifico','Dancing Script','Architects Daughter','Sigmar One','Righteous','Amatic SC','Orbitron','Chewy','Lobster Two','Gloria Hallelujah','Lekton','Almendra Display','Swanky and Moo Moo','Hanalei Fill','Uncial Antiqua','Rouge Script','Engagement','Bonbon','Caesar Dressing','Kenia','Lemon','Stardos Stencil','Bilbo','Macondo','Delius Unicase','Butcherman','Monoton','Nosifer','Codystar','Fontdiner Swanky','Diplomata SC','Snowburst One','Faster One','Rock Salt','Eater','Noto Sans JP','Montserrat','Fira Sans','Baloo Tamma 2','AR One Sans','Alegreya','Anek Kannada','Anek Odia','Anek Tamil','Anek Devanagari');
		$fonts = array_combine($font_array, $font_array);

		$wp_customize->add_setting('wrockmetro_enablefonts',	
			array(
				'default'			=> 'disable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'wrockmetro_customize_sanitize_select'
			));
		
		$wp_customize->add_control('wrockmetro_enablefonts',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Google Fonts','wrock-metro'),
				'settings'   => 'wrockmetro_enablefonts',
				'section' => 'wrockmetro_google_font',
				'choices' => array(
					'enable' => __('Enable','wrock-metro'),
					'disable' => __('Disable','wrock-metro'),
				 ),
			 ));
		
	
		$wp_customize->add_setting(
		'wrockmetro_body_font',
			array(	
			'default'=> 'Open Sans',
			'sanitize_callback' => 'wrockmetro_sanitize_gfont' 
		));

		$wp_customize->add_control(
			'wrockmetro_body_font',array(
					'label' => __('Body Font Family','wrock-metro'),
					'settings' => 'wrockmetro_body_font',
					'section'  => 'wrockmetro_google_font',
					'type' => 'select',
					'choices' => $fonts
			));
		
	

		
		/*********************
		Theme settings.
		*******************/
		$wp_customize->add_section(
			'wrockmetro_theme_settings',
			array(
				'title'       => __( 'Preloading Bar', 'wrock-metro' ),
				'capability'  => 'edit_theme_options',
				'description' => __( 'Effects while loading your website', 'wrock-metro' ),							
				'panel'			=> 'panel_general',
			));			
		
			
			$wp_customize->add_setting('wrockmetro_loading_animation',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'wrockmetro_customize_sanitize_select'
			));
		$wp_customize->add_control('wrockmetro_loading_animation',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Loading Animation','wrock-metro'),
				'settings'   => 'wrockmetro_loading_animation',
				'section' => 'wrockmetro_theme_settings',
				'choices' => array(
					'enable' => __('Enable','wrock-metro'),
					'disable' => __('Disable','wrock-metro'),
				 ),
			 ));

			// Add a control to choose the loading bar color
			$wp_customize->add_setting('wrockmetro_loading_bar_color', array(
				'default' => '#ff3030',
				'transport' => 'refresh',
				'sanitize_callback'	=> 'sanitize_hex_color',
			));

			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'wrockmetro_loading_bar_color', array(
				'label' => __('Loading Bar Color', 'wrock-metro'),
				'section' => 'wrockmetro_theme_settings',
			)));


			$wp_customize->add_section(
				'wrockmetro_scrolltop_section',
				array(
					'title'       => __( 'Scroll To Top', 'wrock-metro' ),
					'capability'  => 'edit_theme_options',						
					'panel'			=> 'panel_general',
				));

			
			//back to top
		$wp_customize->add_setting('wrockmetro_backtotop',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'wrockmetro_customize_sanitize_select'
			));
		$wp_customize->add_control('wrockmetro_backtotop',
			 array (                             
				'type' => 'radio',
				'label' => __('Scroll to Top Button Control','wrock-metro'),
				'settings'   => 'wrockmetro_backtotop',
				'section' => 'wrockmetro_scrolltop_section',
				'choices' => array(
					'enable' => __('Enable','wrock-metro'),
					'disable' => __('Disable','wrock-metro'),
				 ),
			 ));
			 $wp_customize->add_setting(
				'wrockmetro_scroll_top_position',
				array(
					'transport'         => 'postMessage',
					'default'           => 'right',
					'sanitize_callback' => 'wrockmetro_customize_sanitize_select',
				)
			);

			$wp_customize->add_control(
				new wrockmetro_Customizer_Buttonset_Control(
					$wp_customize,
					'wrockmetro_scroll_top_position',
					array(
						'label'           => esc_html__( 'Scroll Button Position', 'wrock-metro' ),
						'section'         => 'wrockmetro_scrolltop_section',
						'settings'        => 'wrockmetro_scroll_top_position',
						'priority'        => 10,
						'choices'         => array(
							'left'  => esc_html__( 'Left', 'wrock-metro' ),
							'right' => esc_html__( 'Right', 'wrock-metro' ),
						),
					)
				)
			);
			
			$wp_customize->add_setting(
		'wrockmetro_scrollcolor_heading',
		array(
			'sanitize_callback' => 'wp_kses',
		));

		$wp_customize->add_control(
		new wrockmetro_Customizer_Heading_Control(
			$wp_customize,
			'wrockmetro_scrollcolor_heading',
			array(
				'label'    => esc_html__( 'Style Customize (Pro Only)', 'wrock-metro' ),
				'section'  => 'wrockmetro_scrolltop_section',
				
			)));
		$wp_customize->add_setting( 'wrockmetro_backtotop_bg' , array(
			'default'     => '#E53B2C',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'wrockmetro_backtotop_bg', array(
		'description'        => __( 'Background Color (Pro Only)', 'wrock-metro' ),
		'section'    => 'wrockmetro_scrolltop_section',
		'settings'   => 'wrockmetro_backtotop_bg',
		) ) );
		$wp_customize->add_setting( 'wrockmetro_backtotop_bghover' , array(
			'default'     => '#9E9E9E',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'wrockmetro_backtotop_bghover', array(
		'description'        => __( 'Background Hover Color (Pro Only)', 'wrock-metro' ),
		'section'    => 'wrockmetro_scrolltop_section',
		'settings'   => 'wrockmetro_backtotop_bghover',
		) ) );
		$wp_customize->add_setting( 'wrockmetro_backtotop_text' , array(
			'default'     => '#ffffff',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'wrockmetro_backtotop_text', array(
		'description'        => __( 'Icon Color (Pro Only)', 'wrock-metro' ),
		'section'    => 'wrockmetro_scrolltop_section',
		'settings'   => 'wrockmetro_backtotop_text',
		) ) );
		$wp_customize->add_setting( 'wrockmetro_backtotop_texthover' , array(
			'default'     => '#333333',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'wrockmetro_backtotop_texthover', array(
		'description'        => __( 'Icon Hover Color (Pro Only)', 'wrock-metro' ),
		'section'    => 'wrockmetro_scrolltop_section',
		'settings'   => 'wrockmetro_backtotop_texthover',
		) ) );


			
			$wp_customize->add_setting('wrockmetro_scrolltop_radius', array(
				'default'           => 5,
				'transport'         => 'postMessage',
				'sanitize_callback' => 'absint', // Sanitize as integer
			));
	
			$wp_customize->add_control('wrockmetro_scrolltop_radius', array(
				'type'        => 'range',
				'section'     => 'wrockmetro_scrolltop_section',
				'settings'    => 'wrockmetro_scrolltop_radius',
				'description' => __('Button Radius (Pro Only)', 'wrock-metro'),
				'priority' => 20,
				'input_attrs' => array(
					'min'  => 1,
					'max'  => 100,
					'step' => 5,
				),
			));	

//Woocommerce Sidebar
		$wp_customize->add_section('wrockmetro_woosidebars_section',
        array(
            'title' => __( 'Sidebar', 'wrock-metro' ),
            'description' => __( 'Sidebar Panel', 'wrock-metro' ),
            'capability'  => 'edit_theme_options',		
            'panel'			=> 'woocommerce',
            'priority'    => apply_filters( 'wrockmetro_sidebars_section_priority', 10 ),
        ));
        $wp_customize->add_setting('wrockmetro_woo_sides',	
        array(
            'default'			=> 'disable',
            'type'				=> 'theme_mod',
            'capability'		=> 'edit_theme_options',
            'sanitize_callback'	=> 'wrockmetro_customize_sanitize_select'
        ));
        $wp_customize->add_control('wrockmetro_woo_sides',
            array (                             
            'type' => 'radio',
            'label' => __('WooCommerce Sidebars','wrock-metro'),
            'settings'   => 'wrockmetro_woo_sides',
            'section' => 'wrockmetro_woosidebars_section',
            'choices' => array(
                'enable' => __('Enable','wrock-metro'),
                'disable' => __('Disable','wrock-metro'),
                ),
            ));
			 
		
		
endif;
	
	 
			 
			
// Theme layout settings.
		$wp_customize->add_section(
			'wrockmetro_theme_layout_options',
			array(
				'title'       => __( 'Theme Layout Settings', 'wrock-metro' ),
				'capability'  => 'edit_theme_options',
				'description' => __( 'Container width and sidebar defaults', 'wrock-metro' ),
				'priority'    => apply_filters( 'wrockmetro_theme_layout_options_priority', 160 ),
			)
		);

		$wp_customize->add_setting(
			'wrockmetro_container_type',
			array(
				'default'           => 'container-box',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'wrockmetro_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new wrockmetro_Image_Radio_Control(
				$wp_customize,
				'wrockmetro_container_type',
				array(
					'label'       => __( 'Container Width', 'wrock-metro' ),
					'description' => __( 'Choose between Fixed or Full width container', 'wrock-metro' ),
					'section'     => 'wrockmetro_theme_layout_options',
					'choices'     => array(
						'container-fluid'  => get_template_directory_uri() . '/images/widthfull.png',
						'container' => get_template_directory_uri() . '/images/widthfixed.png',
						'container-box' => get_template_directory_uri() . '/images/widthbox.png',
					),
					'priority'    => apply_filters( 'wrockmetro_container_type_priority', 10 ),
				)
			));

		$wp_customize->add_setting(
			'wrockmetro_content_background',
			array(
				'default'           => 'contentblock',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'wrockmetro_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new wrockmetro_Image_Radio_Control(
				$wp_customize,
				'wrockmetro_content_background',
				array(
					'label'       => __( 'Content Background (Blended / Separated )', 'wrock-metro' ),
					'description' => __( 'Choose website content Full background or Content only', 'wrock-metro' ),
					'section'     => 'wrockmetro_theme_layout_options',
					'choices'     => array(
						'contentdefault'  => get_template_directory_uri() . '/images/c.png',
						'contentblock' => get_template_directory_uri() . '/images/contentblock.png',
					),
					'priority'    => apply_filters( 'wrockmetro_content_background_priority', 30 ),
				)
			));

	/* 	$wp_customize->add_control(
			new WP_Customize_Control(
				$wp_customize,
				'wrockmetro_container_type',
				array(
					'label'       => __( 'Container Width', 'wrock-metro' ),
					'description' => __( 'Choose between Fixed or Full width container', 'wrock-metro' ),
					'section'     => 'wrockmetro_theme_layout_options',
					'type'        => 'select',
					'choices'     => array(
						'container'       => __( 'Fixed width container', 'wrock-metro' ),
						'container-fluid' => __( 'Full width container', 'wrock-metro' ),
						'container-box' => __( 'Box', 'wrock-metro' ),
					),
					'priority'    => apply_filters( 'wrockmetro_container_type_priority', 10 ),
				)
			)
		); */
	
		

		$wrockmetro_site_info = $wp_customize->get_setting( 'wrockmetro_site_info_override' );
		if ( $wrockmetro_site_info instanceof WP_Customize_Setting ) {
			$wrockmetro_site_info->transport = 'postMessage';
		}
		
		
	}

	
	
} // End of if function_exists( 'wrockmetro_theme_customize_register' ).
add_action( 'customize_register', 'wrockmetro_theme_customize_register' );




if ( ! function_exists( 'wrockmetro_customize_sanitize_select' ) ) {
	function wrockmetro_customize_sanitize_select( $input, $setting ) {

		// Ensure input is a slug (lowercase alphanumeric characters, dashes and underscores are allowed only).
		$input = sanitize_key( $input );

		$control = $setting->manager->get_control( $setting->id );
		if ( ! $control instanceof WP_Customize_Control ) {
			return false;
		}

		// Get the list of possible select options.
		$choices = $control->choices;

		// If the input is a valid key, return it; otherwise, return the default.
		return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
	}
}

function wrockmetro_customize_sanitize_checkbox( $checked ) {
    // Check if the checkbox is checked.
    return ( ( isset( $checked ) && true === $checked ) ? true : false );
}


/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
 
 function wrockmetro_customize_preview_js() {
	$file = '/js/customizer.js';
	$files = '/js/customizer-controls.js';

	$url = get_template_directory_uri() . $file;
	$urls = get_template_directory_uri() . $files;
	$version = filemtime( get_template_directory() . $file );
	if ( false === $version ) {
		$version = time();
	}

	wp_enqueue_script(
		'wrockmetro_customizer_result',
		$url,
		array( 'customize-preview' ),
		(string) $version,
		true
	);
	wp_enqueue_script( 'wrockmetro-customizer-preview', $urls , array( 'customize-preview', 'jquery' ) );
}
add_action( 'customize_preview_init', 'wrockmetro_customize_preview_js' );



function wrockmetro_is_post_meta_enabled($control) {
	return get_theme_mod('wrockmetro_blog_postmeta', 'enable') === 'enable';
}

function wrockmetro_header_selected_styleone($control) {
    return get_theme_mod('wrockmetro_header_style', 'styleone') === 'styleone';
}

function wrockmetro_header_selected_styletwo($control) {
    return get_theme_mod('wrockmetro_header_style', 'styletwo') === 'styletwo';
}

function wrockmetro_header_selected_stylethree($control) {
    return get_theme_mod('wrockmetro_header_style', 'stylethree') === 'stylethree';
}
function wrockmetro_is_readmore_enabled($control) {
	return get_theme_mod('wrockmetro_enable_readmore', 'enable') === 'enable';
}

function wrockmetro_sanitize_gfont( $input ) {
		if ( in_array($input, array('Raleway','Khula','Open Sans','Poppins','Futura','Indie Flower','Droid Sans','Droid Serif','Roboto','Roboto Condensed','Lato','Bree Serif','Oswald','Slabo','Lora','Source Sans Pro','PT Sans','Ubuntu','Lobster','Arimo','Bitter','Noto Sans','Fjalla One','PT Sans Narrow','Poiret One','Passion One','Arvo','Inconsolata','Shadows Into Light','Pacifico','Dancing Script','Architects Daughter','Sigmar One','Righteous','Amatic SC','Orbitron','Chewy','Lobster Two','Gloria Hallelujah','Lekton','Almendra Display','Swanky and Moo Moo','Hanalei Fill','Uncial Antiqua','Rouge Script','Engagement','Bonbon','Caesar Dressing','Kenia','Lemon','Stardos Stencil','Bilbo','Macondo','Delius Unicase','Butcherman','Monoton','Nosifer','Codystar','Fontdiner Swanky','Diplomata SC','Snowburst One','Faster One','Rock Salt','Eater','Noto Sans JP','Montserrat','Fira Sans','Baloo Tamma 2','AR One Sans','Alegreya','Anek Kannada','Anek Odia','Anek Tamil','Anek Devanagari') ) )
			return $input;
		else
			return '';	
	}
	
if ( ! function_exists( 'wrockmetro_headerone' ) ) {
	function wrockmetro_headerone( $current_mod ) {

		if ( 'styletwo' !== get_theme_mod( 'wrockmetro_header_style' ) ) {
			$current_mod = 'enable';
		}

		return $current_mod;
	}
}
add_filter( 'theme_mod_wrockmetro_heroarea', 'wrockmetro_headerone', 30 );	

add_action( 'customize_controls_print_scripts','wrockmetro_enqueue_scripts' );
function wrockmetro_enqueue_scripts() {
	$filess = '/js/customizer-controls.js';

	$urll = get_template_directory_uri() . $filess;
	wp_enqueue_script(
		'wrockmetro-options-reset',
		$urll,
		array( 'jquery' ),
		'2143132',
		false
	);
	
}

add_action( 'wp_ajax_customizer_reset', 'wrockmetro_remove_theme_modifications' );
function wrockmetro_remove_theme_modifications() {
	global $wp_customize, $options;

	// Bail early if we are not in preview mode.
	if ( ! $wp_customize->is_preview() ) {
		wp_send_json_error( 'not_preview' );
	}

	// Bail early if nonce is invalid.
	if ( ! check_ajax_referer( 'customizer-reset', 'nonce', false ) ) {
		wp_send_json_error( 'invalid_nonce' );
	}

	$settings = apply_filters( 'customizer_reset_settings', $wp_customize->settings() );

	if ( ! empty( $settings ) ) {
		foreach ( $settings as $setting ) {
			if ( 'theme_mod' === $setting->type ) {
				remove_theme_mod( $setting->id );
			}
		}
	}
	wp_send_json_success();
}

// Sanitize Select Callback
function wrockmetro_customize_sanitize_selectnew( $input, $setting ) {
    $valid = array(
        'styleone' => __( 'Enable', 'wrock-metro' ),
        'styletwo' => __( 'Disable', 'wrock-metro' ),
    );

    if ( array_key_exists( $input, $valid ) ) {
        return $input;
    } else {
        return '';
    }
}
function wrockmetro_customize_sanitize_selectimage( $input, $setting ) {
    // Retrieve the list of choices from the control.
    $control = $setting->manager->get_control( $setting->id );
    $choices = $control->choices;

    // Validate that the input exists in the choices.
    if ( array_key_exists( $input, $choices ) ) {
        return $input;
    }

    return ''; // Return an empty string for invalid input.
}