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

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function ismoderna_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'ismoderna_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'ismoderna_customize_partial_blogdescription',
			)
		);
		
		
	}
	   /* create panel */
		$wp_customize->add_panel( 'ismoderna_theme_option', array(
			'title'    => __( 'Theme Options', 'ismoderna' ),
			'priority' => 1, // Mixed with top-level-section hierarchy.
		) );
		
		
		
		
		
			/* Ismoderna Theme Footer Section */
		$wp_customize->add_section( 'footer_section', array(
			'title'      => __( 'Footer Options', 'ismoderna' ),
			'panel'      => 'ismoderna_theme_option',
			'capability' => 'edit_theme_options',
			'priority'   => 36,
		) );
		$wp_customize->add_setting( 'ismoderna_footer_section_areas',
		   array(
			  'type'              => 'theme_mod',
			  'default' => '',
			  'sanitize_callback' => 'ismoderna_sanitize_checkbox',
			  'capability'        => 'edit_theme_options',
		   )
		);
		 $wp_customize->add_control(
            new WP_Customize_Control(
                $wp_customize,
                'ismoderna_footer_section_areas',
                array(
                    'label'           => esc_html__( 'Enable Footer Widget Area', 'ismoderna' ),
                    'type'            => 'checkbox',
                    'section'         => 'footer_section',
                    'settings'        => 'ismoderna_footer_section_areas',
                    'priority'        => 1,
                )
            )
        );
		
		
		
		
		
		
		
		/* Ismoderna Theme blog Section */
		$wp_customize->add_section( 'ismoderna_blog_settings', array(
			'title'      => __( 'Blog Page Settings', 'ismoderna' ),
			'panel'      => 'ismoderna_theme_option',
			'capability' => 'edit_theme_options',
			'priority'   => 35,
		) );
		
		$wp_customize->add_setting( 'blog_content',
		   array(
			  'type'              => 'theme_mod',
			  'default' => '',
			  'sanitize_callback' => 'absint',
			  'capability'        => 'edit_theme_options',
		   )
		);
		
		$wp_customize->add_control( 'blog_content',
		   array(
			  'label' => __( 'Choose content option','ismoderna' ),
			  'section' => 'ismoderna_blog_settings',
			  'priority' => 10,
			  'type' => 'select',
			  'capability' => 'edit_theme_options',
			  'choices' => 
					array( 
						'1' => __( 'Excerpt','ismoderna' ),
						'2' => __( 'Full-Content','ismoderna' ),
					)
		    )
		);

		/* Ismoderna Theme Sidebar Section */
		$wp_customize->add_section( 'ismoderna_Sidebar_Settings_Section', array(
			'title'      => __( 'Sidebar Section', 'ismoderna' ),
			'panel'      => 'ismoderna_theme_option',
			'capability' => 'edit_theme_options',
			'priority'   => 34,
		) );
		
		$wp_customize->add_setting( 'ismoderna_Page_Sidebar_Settings',
		   array(
			  'type'              => 'theme_mod',
			  'default' => '',
			  'sanitize_callback' => 'ismoderna_Sidebar_Section_Page_Sanitize_Text',
			  'capability'        => 'edit_theme_options',
		   )
		);
		
		$wp_customize->add_control( 'ismoderna_Page_Sidebar_Settings',
		    array(
				'label' => __( 'Page Sidebar','ismoderna' ),
				'section' => 'ismoderna_Sidebar_Settings_Section',
				'priority' => 10,
				'type' => 'select',
				'capability' => 'edit_theme_options',
				'choices' => 
				array( 
					'No_Sidebar' => __( 'No Sidebar','ismoderna' ),
					'Left_Sidebar' => __( 'Left Sidebar','ismoderna' ),
					'Right_Sidebar' => __( 'Right Sidebar','ismoderna' ),
			    )
		   )
		);

		$wp_customize->add_setting( 'ismoderna_Blog_Sidebar_Settings',
			array(
			'type'              => 'theme_mod',
			'default' => '',
			'sanitize_callback' => 'ismoderna_Sidebar_Section_Page_Sanitize_Text',
			'capability'        => 'edit_theme_options',
			)
		);
		
		$wp_customize->add_control( 'ismoderna_Blog_Sidebar_Settings',
			array(
				'label' => __( 'Blog Post Sidebar','ismoderna' ),
				'section' => 'ismoderna_Sidebar_Settings_Section',
				'priority' => 10,
				'type' => 'select',
				'capability' => 'edit_theme_options',
				'choices' => array( 
					'Blog_No_Sidebar' => __( 'No Sidebar','ismoderna' ),
					'Blog_Left_Sidebar' => __( 'Left Sidebar','ismoderna' ),
					'Blog_Right_Sidebar' => __( 'Right Sidebar','ismoderna' ),
				)
			)
		);

		$wp_customize->add_setting( 'ismoderna_Archive_Pages_Sidebar_Settings',
			array(
			'type'              => 'theme_mod',
			'default' => '',
			'sanitize_callback' => 'ismoderna_Sidebar_Section_Page_Sanitize_Text',
			'capability'        => 'edit_theme_options',
			)
		);
		
		$wp_customize->add_control( 'ismoderna_Archive_Pages_Sidebar_Settings',
			array(
				'label' => __( 'Archive Post Sidebar','ismoderna' ),
				'section' => 'ismoderna_Sidebar_Settings_Section',
				'priority' => 10,
				'type' => 'select',
				'capability' => 'edit_theme_options',
				'choices' => array( 
					'Archive_No_Sidebar' => __( 'No Sidebar','ismoderna' ),
					'Archive_Left_Sidebar' => __( 'Left Sidebar','ismoderna' ),
					'Archive_Right_Sidebar' => __( 'Right Sidebar','ismoderna' ),
				)
			)
		);
		
		$wp_customize->add_setting( 'ismoderna_enable_scroll', 
				array(
				 'type' => 'theme_mod',
				 'default'=>1,
				 'sanitize_callback' => 'ismoderna_sanitize_checkbox',
			));
			
			$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'ismoderna_enable_scroll', array(
			'type'=>'checkbox',
			'label'   => esc_html__('Enable Scroll to top button','ismoderna'),
			'section' => 'ismoderna_Sidebar_Settings_Section',
			)));

	    // Sanitize Text Function For Sidebar Section
		function ismoderna_Sidebar_Section_Page_Sanitize_Text( $text ) {
		    return sanitize_text_field( $text );
		}	
		
		function ismoderna_sanitize_checkbox( $checked ) {
			// Boolean check.
			return ( ( isset( $checked ) && true == $checked ) ? true : false );
		}
		
		
// Typography Settings start.	
function ismoderna_sanitize_text( $input ) {
    return wp_kses_post( force_balance_tags( $input ) );
}
function ismoderna_theme_sanitize_checkbox( $input ) {
   if ( $input == 1 ) {
        return 'on' ;
    } else {
        return 'off';
    }
}
function ismoderna_sanitize_integer( $input ) {
    return (int)($input);
}
// Typography Settings end.
			
}
add_action( 'customize_register', 'ismoderna_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function ismoderna_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function ismoderna_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function ismoderna_customize_preview_js() {
	wp_enqueue_script( 'ismoderna-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '', true );
}
add_action( 'customize_preview_init', 'ismoderna_customize_preview_js' );