<?php
/**
 * Digital Theme Customizer
 *
 * @package Digital
 */

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

if ( ! function_exists( 'digital_customize_register' ) ) {
	
	
	
	/**
	 * Register basic support (site title, header text color) for the Theme Customizer.
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer reference.
	 */
	function digital_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'     => 'digital_customize_partial_custom_logo',
				'container_inclusive' => false,
			)
		);
		
		
	}
}
add_action( 'customize_register', 'digital_customize_register' );


if ( ! function_exists( 'digital_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 digital_customize_partial_custom_logo() {
		if ( has_custom_logo() ) {
			return get_custom_logo();
		} else {
			return get_bloginfo( 'name' );
		}
	}
}


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

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


		class digital_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 Digital_Important_Links extends WP_Customize_Control {
				public $type = "digital-important-links";
				public function render_content() {
				
				echo '<ul><b>
					<li>' . esc_attr__( '* Fully Mobile Responsive', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Dedicated Option Panel', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Customize Theme Color', 'digital' ) . '</li>
					<li>' . esc_attr__( '* WooCommerce & bbPress Support', 'digital' ) . '</li>
					<li>' . esc_attr__( '* SEO Optimized', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Control Individual Meta Option like: Category, date, Author, Tags etc. ', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Full Support', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Google Fonts', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Theme Color Customization', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Custom CSS', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Website Layout', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Select Number of Columns', 'digital' ) . '</li>
					<li>' . esc_attr__( '* Website Width Control', 'digital' ) . '</li>
					</b></ul>
				';
				$important_links = array(		 
					'theme-info' => array(
						'link' => esc_url('https://www.insertcart.com/product/digital-wp-theme/'),
						'text' => __('Digital Pro', 'digital'),
					),
					'support' => array(
						'link' => esc_url('https://www.insertcart.com/contact-us/'),
						'text' => __('Contact us', 'digital'),
					),         
					'Documentation' => array(
						'link' => esc_url('https://www.insertcart.com/digital-theme-documentation-setup/'),
						'text' => __('Documentation', 'digital'),
					),			 
				);
				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('digital_important_links', array(
				'priority' => 1,
				'title' => __('Upgrade to Pro', 'digital'),
				));
		
				$wp_customize->add_setting('digital_important_links', array(
					'capability' => 'edit_theme_options',
					'sanitize_callback' => 'wrockmetro_links_sanitize'
				));
		
				$wp_customize->add_control(new Digital_Important_Links($wp_customize, 'important_links', array(
					'section' => 'digital_important_links',
					'settings' => 'digital_important_links'
				)));	 
			
		
	

class digital_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='digital-img-container'>
            <?php
            foreach ($this->choices as $value => $label) :
                $class = ($this->value() == $value) ? 'digital-radio-img-selected digital-radio-img-img' : 'digital-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='digital-radio-img digital-radio-img-<?php echo esc_attr($value); ?>' />
                    </label>
                </li>
                <?php
            endforeach;
            ?>
        </ul>
		<script>
            (function ($) {
				
                wp.customize.control('digital_posts_layout', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

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

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

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

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

                        // Remove the 'digital-radio-img-selected' class from all images
                        $('ul#digital-img-container img').removeClass('digital-radio-img-selected');
                        // Add the 'digital-radio-img-selected' class to the selected image
                        $('ul#digital-img-container img.digital-radio-img-' + value).addClass('digital-radio-img-selected');
                    });
                });
				
				
            })(jQuery);
        </script>
			<?php
		}
	}
		
	if ( class_exists( 'WP_Customize_Panel' ) ):
	$wp_customize->register_control_type('digital_Customizer_Heading_Control');
	
	$digital_inc_dir = 'inc';
	$digital_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/tagcloudcontrol.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 ( $digital_includes_controls as $file ) {
		require_once get_theme_file_path( $digital_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' => 'digital_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', 'digital' ),
		)
	);

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

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'digital_browser_color', array(
		'label' => __('Default Browser Color (Effect only Mobile)', 'digital'),
		'section' => 'colors',
		'settings' => 'digital_browser_color',
	)));		
		
		$wp_customize->add_section('custom_section_css',
				array(
					'title'			=> __( 'Custom CSS', 'digital' ),			
					'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', 'digital' ),
			'description'	=> __( 'Define custom CSS be used for your site. Do not enclose in script tags.', 'digital' ),
		)
	);
	
		/*********************
		Menu settings. Style One
		*******************/
		$wp_customize->add_section(
			'digital_menu_settings',
			array(
				'title'       => __( 'Menu Settings', 'digital' ),
				'description'       => __( 'Menu Settings', 'digital' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'panel_general',
			)
		);
		
		$wp_customize->add_setting('digital_topside',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'digital_customize_sanitize_select'
			));
		$wp_customize->add_control('digital_topside',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Woocommerce/Search Bar in Right','digital'),
				'settings'   => 'digital_topside',
				'section' => 'digital_theme_settings',
				'choices' => array(
					'enable' => __('Enable','digital'),
					'disable' => __('Disable','digital'),
				 ),
			 ));		

		
		/*********************
		Social Links
		*******************/
		$wp_customize->add_section('digital_sociallinks',
			array(
				'title'       => __( 'Social Links', 'digital' ),
				'description'       => __( 'Author Profile Control on Posts and Archive Pages (Make Sure to fill all detail to show profile in Dashboard > Users > Profile)', 'digital' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'digital_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', 'digital'),
        'section' => 'digital_sociallinks',
        'type' => 'select',
        'choices' => array(
            'rounded' => __('Round', 'digital'),
            'rounded-circle' => __('Circle', 'digital'),
            'rounded-0' => __('Tile', 'digital'),
        ),
    ));	
	$social_media_platforms = array(
        'facebook' => __('Facebook', 'digital'),
        'twitter' => __('Twitter', 'digital'),
        'whatsapp' => __('WhatsApp', 'digital'),
        'calling' => __('Calling', 'digital'),
        'youtube' => __('YouTube', 'digital'),
		'telegram' => __('Telegram', 'digital'),
    );

    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' => 'digital_sociallinks',
            'type' => 'text',
        ));
    }
		
		/*********************
		Google Fonts
		*******************/
		$wp_customize->add_section('digital_google_font',
			array(
				'title'       => __( 'Google Fonts', 'digital' ),
				'description'       => __( 'Google Fonts Settings', 'digital' ),
				'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('digital_enablefonts',	
			array(
				'default'			=> 'disable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'digital_customize_sanitize_select'
			));
		
		$wp_customize->add_control('digital_enablefonts',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Google Fonts','digital'),
				'settings'   => 'digital_enablefonts',
				'section' => 'digital_google_font',
				'choices' => array(
					'enable' => __('Enable','digital'),
					'disable' => __('Disable','digital'),
				 ),
			 ));
		
	
		$wp_customize->add_setting(
		'digital_body_font',
			array(	
			'default'=> 'Open Sans',
			'sanitize_callback' => 'digital_sanitize_gfont' 
		));

		$wp_customize->add_control(
			'digital_body_font',array(
					'label' => __('Body Font Family','digital'),
					'settings' => 'digital_body_font',
					'section'  => 'digital_google_font',
					'type' => 'select',
					'choices' => $fonts
			));
		
	

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

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

			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'digital_loading_bar_color', array(
				'label' => __('Loading Bar Color', 'digital'),
				'section' => 'digital_theme_settings',
			)));

/*********************
	Scroll To Top
	*******************/
			$wp_customize->add_section(
				'digital_scrolltop_section',
				array(
					'title'       => __( 'Scroll To Top', 'digital' ),
					'capability'  => 'edit_theme_options',						
					'panel'			=> 'panel_general',
				));

			
			//back to top
		$wp_customize->add_setting('digital_backtotop',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'digital_customize_sanitize_select'
			));
		$wp_customize->add_control('digital_backtotop',
			 array (                             
				'type' => 'radio',
				'label' => __('Scroll to Top Button Control','digital'),
				'settings'   => 'digital_backtotop',
				'section' => 'digital_scrolltop_section',
				'choices' => array(
					'enable' => __('Enable','digital'),
					'disable' => __('Disable','digital'),
				 ),
			 ));


			 $wp_customize->add_setting(
				'digital_scroll_top_position',
				array(
					'transport'         => 'postMessage',
					'default'           => 'right',
					'sanitize_callback' => 'digital_customize_sanitize_select',
				)
			);

			$wp_customize->add_control(
				new digital_Customizer_Buttonset_Control(
					$wp_customize,
					'digital_scroll_top_position',
					array(
						'label'           => esc_html__( 'Scroll Button Position', 'digital' ),
						'section'         => 'digital_scrolltop_section',
						'settings'        => 'digital_scroll_top_position',
						'priority'        => 10,
						'choices'         => array(
							'left'  => esc_html__( 'Left', 'digital' ),
							'right' => esc_html__( 'Right', 'digital' ),
						),
					)
				)
			);
			 $wp_customize->add_setting(
				'digital_scrollcolor_heading',
				array(
					'sanitize_callback' => 'wp_kses',
				));
		
				$wp_customize->add_control(
				new digital_Customizer_Heading_Control(
					$wp_customize,
					'digital_scrollcolor_heading',
					array(
						'label'    => esc_html__( 'Style Customize (Pro Only)', 'digital' ),
						'section'  => 'digital_scrolltop_section',
						
					)));	

		$wp_customize->add_setting( 'digital_backtotop_bg' , array(
			'default'     => '#000000',
			'transport'   => 'refresh',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'digital_backtotop_bg', array(
		'description'        => __( 'Background Color', 'digital' ),
		'section'    => 'digital_scrolltop_section',
		'settings'   => 'digital_backtotop_bg',
		) ) );
		$wp_customize->add_setting( 'digital_backtotop_bghover' , array(
			'default'     => '#9E9E9E',
			'transport'   => 'refresh',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'digital_backtotop_bghover', array(
		'description'        => __( 'Background Hover Color', 'digital' ),
		'section'    => 'digital_scrolltop_section',
		'settings'   => 'digital_backtotop_bghover',
		) ) );
		$wp_customize->add_setting( 'digital_backtotop_text' , array(
			'default'     => '#ffffff',
			'transport'   => 'refresh',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'digital_backtotop_text', array(
		'description'        => __( 'Icon Color', 'digital' ),
		'section'    => 'digital_scrolltop_section',
		'settings'   => 'digital_backtotop_text',
		) ) );
		$wp_customize->add_setting( 'digital_backtotop_texthover' , array(
			'default'     => '#333333',
			'transport'   => 'refresh',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'digital_backtotop_texthover', array(
		'description'        => __( 'Icon Hover Color', 'digital' ),
		'section'    => 'digital_scrolltop_section',
		'settings'   => 'digital_backtotop_texthover',
		) ) );


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


/*********************
	Text Selection
	*******************/
	$wp_customize->add_section(
		'digital_textselection_section',
		array(
			'title'       => __( 'Text Selection', 'digital' ),
			'capability'  => 'edit_theme_options',						
			'panel'			=> 'panel_general',
		));
$wp_customize->add_setting( 'digital_selection_bg' , array(
	'default'     => '#39a1eb',
	'transport'   => 'refresh',
	'sanitize_callback'	=> 'sanitize_hex_color',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'digital_selection_bg', array(
'description'        => __( 'Selection Background Color', 'digital' ),
'section'    => 'digital_textselection_section',
'settings'   => 'digital_selection_bg',
) ) );
$wp_customize->add_setting( 'digital_selection_text' , array(
	'default'     => '#ffffff',
	'transport'   => 'refresh',
	'sanitize_callback'	=> 'sanitize_hex_color',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'digital_selection_text', array(
'description'        => __( 'Text Color', 'digital' ),
'section'    => 'digital_textselection_section',
'settings'   => 'digital_selection_text',
) ) );

/*********************
    Schema Markup
    *******************/
	$wp_customize->add_section('digital_schema_markup',
    array(
        'title'       => __( 'Schema', 'digital' ),
        'capability'  => 'edit_theme_options',						
        'panel'			=> 'panel_general',
        'priority'    => apply_filters( 'digital_postnavi_section_priority', 10 ),
    ));
$wp_customize->add_setting(
    'digital_enable_schema',
    array(
        'capability'        => 'edit_theme_options',
        'default'           => false,
        'sanitize_callback' => 'digital_customize_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'digital_enable_schema',
    array(
        'type'    => 'checkbox',
        'section' => 'digital_schema_markup',
        'label'   => esc_html__( 'Enable Schema', 'digital' ),
    )
);
//Woocommerce Sidebar
		$wp_customize->add_section('digital_woosidebars_section',
        array(
            'title' => __( 'Sidebar', 'digital' ),
            'description' => __( 'Sidebar Panel', 'digital' ),
            'capability'  => 'edit_theme_options',		
            'panel'			=> 'woocommerce',
            'priority'    => apply_filters( 'digital_sidebars_section_priority', 10 ),
        ));
        $wp_customize->add_setting('digital_woo_sides',	
        array(
            'default'			=> 'disable',
            'type'				=> 'theme_mod',
            'capability'		=> 'edit_theme_options',
            'sanitize_callback'	=> 'digital_customize_sanitize_select'
        ));
        $wp_customize->add_control('digital_woo_sides',
            array (                             
            'type' => 'radio',
            'label' => __('WooCommerce Sidebars','digital'),
            'settings'   => 'digital_woo_sides',
            'section' => 'digital_woosidebars_section',
            'choices' => array(
                'enable' => __('Enable','digital'),
                'disable' => __('Disable','digital'),
                ),
            ));
			 
endif;	 
			 
			
// Theme layout settings.
		$wp_customize->add_section(
			'digital_theme_layout_options',
			array(
				'title'       => __( 'Theme Layout Settings', 'digital' ),
				'capability'  => 'edit_theme_options',
				'description' => __( 'Container width and sidebar defaults', 'digital' ),
				'priority'    => apply_filters( 'digital_theme_layout_options_priority', 160 ),
			)
		);

		$wp_customize->add_setting(
			'digital_container_type',
			array(
				'default'           => 'container-box',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'digital_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new digital_Image_Radio_Control(
				$wp_customize,
				'digital_container_type',
				array(
					'label'       => __( 'Container Width', 'digital' ),
					'description' => __( 'Choose between Fixed or Full width container', 'digital' ),
					'section'     => 'digital_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( 'digital_container_type_priority', 10 ),
				)
			));

		$wp_customize->add_setting(
			'digital_content_background',
			array(
				'default'           => 'contentdefault',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'digital_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new digital_Image_Radio_Control(
				$wp_customize,
				'digital_content_background',
				array(
					'label'       => __( 'Content Background (Blended / Separated )', 'digital' ),
					'description' => __( 'Choose website content Full background or Content only', 'digital' ),
					'section'     => 'digital_theme_layout_options',
					'choices'     => array(
						'contentdefault'  => get_template_directory_uri() . '/images/c.png',
						'contentblock' => get_template_directory_uri() . '/images/contentblock.png',
					),
					'priority'    => apply_filters( 'digital_container_type_priority', 30 ),
				)
			));

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

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


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

if ( ! function_exists( 'digital_customize_sanitize_select' ) ) {
	function digital_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 );
	}
}



/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
 
 function digital_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(
		'digital_customizer_result',
		$url,
		array( 'customize-preview' ),
		(string) $version,
		true
	);
	wp_enqueue_script( 'digital-customizer-preview', $url , array( 'customize-preview', 'jquery' ) );
}
add_action( 'customize_preview_init', 'digital_customize_preview_js' );



function digital_is_post_meta_enabled($control) {
	return get_theme_mod('digital_blog_postmeta', 'enable') === 'enable';
}

function digital_header_selected_styleone($control) {
    return get_theme_mod('digital_header_style', 'styleone') === 'styleone';
}

function digital_header_selected_styletwo($control) {
    return get_theme_mod('digital_header_style', 'styletwo') === 'styletwo';
}

function digital_header_selected_stylethree($control) {
    return get_theme_mod('digital_header_style', 'stylethree') === 'stylethree';
}

function digital_header_selected_stylefour($control) {
    return get_theme_mod('digital_header_style', 'stylefour') === 'stylefour';
}

function digital_header_selected_stylefive($control) {
    return get_theme_mod('digital_header_style', 'stylefive') === 'stylefive';
}

function digital_header_selected_stylesix($control) {
    return get_theme_mod('digital_header_style', 'stylesix') === 'stylesix';
}
function digital_is_readmore_enabled($control) {
	return get_theme_mod('digital_enable_readmore', 'enable') === 'enable';
}

function digital_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( 'digital_headerone' ) ) {
	function digital_headerone( $current_mod ) {

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

		return $current_mod;
	}
}
add_filter( 'theme_mod_digital_heroarea', 'digital_headerone', 30 );	

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

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

add_action( 'wp_ajax_customizer_reset', 'digital_remove_theme_modifications' );
function digital_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 digital_customize_sanitize_selectnew( $input, $setting ) {
    $valid = array(
        'styleone' => __( 'Enable', 'digital' ),
        'styletwo' => __( 'Disable', 'digital' ),
    );

    if ( array_key_exists( $input, $valid ) ) {
        return $input;
    } else {
        return '';
    }
}
