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

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

if ( ! function_exists( 'poster_customize_register' ) ) {
	
	
	
	/**
	 * Register basic support (site title, header text color) for the Theme Customizer.
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer reference.
	 */
	function poster_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'     => 'poster_customize_partial_custom_logo',
				'container_inclusive' => false,
			)
		);
		
		class poster_Important_Links extends WP_Customize_Control {

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

      public function render_content() {
      
		 echo '<ul><b>
			<li>' . esc_attr__( '* Fully Mobile Responsive', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Dedicated Option Panel', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Customize Theme Color', 'poster' ) . '</li>
			<li>' . esc_attr__( '* WooCommerce & bbPress Support', 'poster' ) . '</li>
			<li>' . esc_attr__( '* SEO Optimized', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Control Individual Meta Option like: Category, date, Author, Tags etc. ', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Full Support', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Google Fonts', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Theme Color Customization', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Custom CSS', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Website Layout', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Select Number of Columns', 'poster' ) . '</li>
			<li>' . esc_attr__( '* Website Width Control', 'poster' ) . '</li>
			</b></ul>
		 ';
         $important_links = array(
		 
            'theme-info' => array(
               'link' => esc_url('https://www.insertcart.com/product/poster-pro-wordpress-theme/'),
               'text' => __('Poster Pro', 'poster'),
            ),
            'support' => array(
               'link' => esc_url('https://www.insertcart.com/contact-us/'),
               'text' => __('Contact us', 'poster'),
            ),         
			'Documentation' => array(
               'link' => esc_url('https://www.insertcart.com/poster-theme-setup-guide/'),
               'text' => __('Documentation', 'poster'),
            ),			 
         );
         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('poster_important_links', array(
      'priority' => 1,
      'title' => __('Upgrade to Pro', 'poster'),
	   ));

	   $wp_customize->add_setting('poster_important_links', array(
		  'capability' => 'edit_theme_options',
		  'sanitize_callback' => 'poster_links_sanitize'
	   ));

	   $wp_customize->add_control(new poster_Important_Links($wp_customize, 'important_links', array(
		  'section' => 'poster_important_links',
		  'settings' => 'poster_important_links'
	   )));	 
	}
}
add_action( 'customize_register', 'poster_customize_register' );


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


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

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


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

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

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

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

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

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

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

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

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

    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' => 'poster_sociallinks',
            'type' => 'text',
        ));
    }
		
		/*********************
		Google Fonts
		*******************/
		$wp_customize->add_section('poster_google_font',
			array(
				'title'       => __( 'Google Fonts', 'poster' ),
				'description'       => __( 'Google Fonts Settings', 'poster' ),
				'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('poster_enablefonts',	
			array(
				'default'			=> 'disable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'poster_customize_sanitize_select'
			));
		
		$wp_customize->add_control('poster_enablefonts',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Google Fonts','poster'),
				'settings'   => 'poster_enablefonts',
				'section' => 'poster_google_font',
				'choices' => array(
					'enable' => __('Enable','poster'),
					'disable' => __('Disable','poster'),
				 ),
			 ));
		
	
		$wp_customize->add_setting(
		'poster_body_font',
			array(	
			'default'=> 'Open Sans',
			'sanitize_callback' => 'poster_sanitize_gfont' 
		));

		$wp_customize->add_control(
			'poster_body_font',array(
					'label' => __('Body Font Family','poster'),
					'settings' => 'poster_body_font',
					'section'  => 'poster_google_font',
					'type' => 'select',
					'choices' => $fonts
			));
		
	

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

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

			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'poster_loading_bar_color', array(
				'label' => __('Loading Bar Color', 'poster'),
				'section' => 'poster_theme_settings',
			)));


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

			
			//back to top
		$wp_customize->add_setting('poster_backtotop',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'poster_customize_sanitize_select'
			));
		$wp_customize->add_control('poster_backtotop',
			 array (                             
				'type' => 'radio',
				'label' => __('Scroll to Top Button Control','poster'),
				'settings'   => 'poster_backtotop',
				'section' => 'poster_scrolltop_section',
				'choices' => array(
					'enable' => __('Enable','poster'),
					'disable' => __('Disable','poster'),
				 ),
			 ));
			 $wp_customize->add_setting(
				'poster_scroll_top_position',
				array(
					'transport'         => 'postMessage',
					'default'           => 'right',
					'sanitize_callback' => 'poster_customize_sanitize_select',
				)
			);

			$wp_customize->add_control(
				new poster_Customizer_Buttonset_Control(
					$wp_customize,
					'poster_scroll_top_position',
					array(
						'label'           => esc_html__( 'Scroll Button Position', 'poster' ),
						'section'         => 'poster_scrolltop_section',
						'settings'        => 'poster_scroll_top_position',
						'priority'        => 10,
						'choices'         => array(
							'left'  => esc_html__( 'Left', 'poster' ),
							'right' => esc_html__( 'Right', 'poster' ),
						),
					)
				)
			);
		$wp_customize->add_setting( 'poster_backtotop_bg' , array(
			'default'     => '#E53B2C',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'poster_backtotop_bg', array(
		'description'        => __( 'Background Color (Pro Only)', 'poster' ),
		'section'    => 'poster_scrolltop_section',
		'settings'   => 'poster_backtotop_bg',
		) ) );
		$wp_customize->add_setting( 'poster_backtotop_bghover' , array(
			'default'     => '#9E9E9E',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'poster_backtotop_bghover', array(
		'description'        => __( 'Background Hover Color (Pro Only)', 'poster' ),
		'section'    => 'poster_scrolltop_section',
		'settings'   => 'poster_backtotop_bghover',
		) ) );
		$wp_customize->add_setting( 'poster_backtotop_text' , array(
			'default'     => '#ffffff',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'poster_backtotop_text', array(
		'description'        => __( 'Icon Color (Pro Only)', 'poster' ),
		'section'    => 'poster_scrolltop_section',
		'settings'   => 'poster_backtotop_text',
		) ) );
		$wp_customize->add_setting( 'poster_backtotop_texthover' , array(
			'default'     => '#333333',
			'transport'   => 'postMessage',
			'sanitize_callback'	=> 'sanitize_hex_color',
		) );
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'poster_backtotop_texthover', array(
		'description'        => __( 'Icon Hover Color (Pro Only)', 'poster' ),
		'section'    => 'poster_scrolltop_section',
		'settings'   => 'poster_backtotop_texthover',
		) ) );


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

//Woocommerce Sidebar
		$wp_customize->add_section('poster_woosidebars_section',
        array(
            'title' => __( 'Sidebar', 'poster' ),
            'description' => __( 'Sidebar Panel', 'poster' ),
            'capability'  => 'edit_theme_options',		
            'panel'			=> 'woocommerce',
            'priority'    => apply_filters( 'poster_sidebars_section_priority', 10 ),
        ));
        $wp_customize->add_setting('poster_woo_sides',	
        array(
            'default'			=> 'disable',
            'type'				=> 'theme_mod',
            'capability'		=> 'edit_theme_options',
            'sanitize_callback'	=> 'poster_customize_sanitize_select'
        ));
        $wp_customize->add_control('poster_woo_sides',
            array (                             
            'type' => 'radio',
            'label' => __('WooCommerce Sidebars','poster'),
            'settings'   => 'poster_woo_sides',
            'section' => 'poster_woosidebars_section',
            'choices' => array(
                'enable' => __('Enable','poster'),
                'disable' => __('Disable','poster'),
                ),
            ));
			 
		
		
endif;
	
	 
			 
			
// Theme layout settings.
		$wp_customize->add_section(
			'poster_theme_layout_options',
			array(
				'title'       => __( 'Theme Layout Settings', 'poster' ),
				'capability'  => 'edit_theme_options',
				'description' => __( 'Container width and sidebar defaults', 'poster' ),
				'priority'    => apply_filters( 'poster_theme_layout_options_priority', 160 ),
			)
		);

		$wp_customize->add_setting(
			'poster_container_type',
			array(
				'default'           => 'container-box',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'poster_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new poster_Image_Radio_Control(
				$wp_customize,
				'poster_container_type',
				array(
					'label'       => __( 'Container Width', 'poster' ),
					'description' => __( 'Choose between Fixed or Full width container', 'poster' ),
					'section'     => 'poster_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( 'poster_container_type_priority', 10 ),
				)
			));

		$wp_customize->add_setting(
			'poster_content_background',
			array(
				'default'           => 'contentblock',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'poster_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new poster_Image_Radio_Control(
				$wp_customize,
				'poster_content_background',
				array(
					'label'       => __( 'Content Background (Blended / Separated )', 'poster' ),
					'description' => __( 'Choose website content Full background or Content only', 'poster' ),
					'section'     => 'poster_theme_layout_options',
					'choices'     => array(
						'contentdefault'  => get_template_directory_uri() . '/images/c.png',
						'contentblock' => get_template_directory_uri() . '/images/contentblock.png',
					),
					'priority'    => apply_filters( 'poster_content_background_priority', 30 ),
				)
			));

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

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

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




if ( ! function_exists( 'poster_customize_sanitize_select' ) ) {
	function poster_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 poster_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 poster_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(
		'poster_customizer_result',
		$url,
		array( 'customize-preview' ),
		(string) $version,
		true
	);
	wp_enqueue_script( 'poster-customizer-preview', $urls , array( 'customize-preview', 'jquery' ) );
}
add_action( 'customize_preview_init', 'poster_customize_preview_js' );



function poster_is_post_meta_enabled($control) {
	return get_theme_mod('poster_blog_postmeta', 'enable') === 'enable';
}

function poster_header_selected_styleone($control) {
    return get_theme_mod('poster_header_style', 'styleone') === 'styleone';
}

function poster_header_selected_styletwo($control) {
    return get_theme_mod('poster_header_style', 'styletwo') === 'styletwo';
}

function poster_header_selected_stylethree($control) {
    return get_theme_mod('poster_header_style', 'stylethree') === 'stylethree';
}
function poster_is_readmore_enabled($control) {
	return get_theme_mod('poster_enable_readmore', 'enable') === 'enable';
}

function poster_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( 'poster_headerone' ) ) {
	function poster_headerone( $current_mod ) {

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

		return $current_mod;
	}
}
add_filter( 'theme_mod_poster_heroarea', 'poster_headerone', 30 );	

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

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

add_action( 'wp_ajax_customizer_reset', 'poster_remove_theme_modifications' );
function poster_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 poster_customize_sanitize_selectnew( $input, $setting ) {
    $valid = array(
        'styleone' => __( 'Enable', 'poster' ),
        'styletwo' => __( 'Disable', 'poster' ),
    );

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