<?php
function electromix_blog_setting( $wp_customize ) {
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	/*=========================================
	Frontpage
	=========================================*/
	$wp_customize->add_panel(
		'electromix_frontpage_sections', array(
			'priority' => 32,
			'title' => esc_html__( 'Frontpage Sections', 'electromix' ),
		)
	);
	/*=========================================
	Blog Section
	=========================================*/
	$wp_customize->add_section(
		'blog_setting', array(
			'title' => esc_html__( 'Blog Section', 'electromix' ),
			'priority' => 1000,
			'panel' => 'electromix_frontpage_sections',
		)
	);
	
	/*=========================================
	Setting
	=========================================*/
	// Setting
	$wp_customize->add_setting(
		'blog_setting_head'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			'priority' => 4,
		)
	);

	$wp_customize->add_control(
	'blog_setting_head',
		array(
			'type' => 'hidden',
			'label' => __('Setting','electromix'),
			'section' => 'blog_setting',
		)
	);
	
	// Hide/Show
	$wp_customize->add_setting(
		'blog_setting_hs'
			,array(
			'default'     	=> '1',
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_checkbox',
			'priority' => 4,
		)
	);

	$wp_customize->add_control(
	'blog_setting_hs',
		array(
			'type' => 'checkbox',
			'label' => __('Hide/Show','electromix'),
			'section' => 'blog_setting',
		)
	);
	/*=========================================
	Header
	=========================================*/
	$wp_customize->add_setting(
		'blog_header'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			'priority' => 1,
		)
	);

	$wp_customize->add_control(
	'blog_header',
		array(
			'type' => 'hidden',
			'label' => __('Header','electromix'),
			'section' => 'blog_setting',
		)
	);
	
	$wp_customize->add_setting(
		'blog_ttl_icon',
		array(
			'default' => 'fa-list',
			'sanitize_callback' => 'sanitize_text_field',
			'capability' => 'edit_theme_options',
		)
	);	

	$wp_customize->add_control(new Electromix_Icon_Picker_Control($wp_customize, 
		'blog_ttl_icon',
		array(
			'label'   		=> __('Icon','electromix'),
			'section' 		=> 'blog_setting',
			'iconset' => 'fa',
			
		))  
	);
	
	//  Title // 
	$wp_customize->add_setting(
    	'blog_ttl',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_html',
			'transport'         => $selective_refresh,
			'priority' => 2,
		)
	);	
	
	$wp_customize->add_control( 
		'blog_ttl',
		array(
		    'label'   => __('Title','electromix'),
		    'section' => 'blog_setting',
			'type'           => 'text',
		)  
	);
	
	//Timer	
	$wp_customize->add_setting(
		'blog_time_head'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
		)
	);

	$wp_customize->add_control(
	'blog_time_head',
		array(
			'type' => 'hidden',
			'label' => __('Time','electromix'),
			'section' => 'blog_setting',
		)
	);
	
	$wp_customize->add_setting(
    	'blog_timer_date',
    	array(
	        'default'			=> __('2030-12-31','electromix'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_html',
		)
	);	
	$wp_customize->add_control( 
		'blog_timer_date',
		array(
		    'section' => 'blog_setting',
			'type'     => 'date',
		)  
	);
	
	$wp_customize->add_setting(
    	'blog_timer_time',
    	array(
	        'default'			=> __('00:00','electromix'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_html',
		)
	);
	
	$wp_customize->add_control( 
		'blog_timer_time',
		array(
		    'section' => 'blog_setting',
			'type'     => 'time',
		)  
	);
	
	
	/*=========================================
	Content
	=========================================*/
		
	// No. of Products Display
	if ( class_exists( 'Ecommerce_Comp_Customizer_Range_Control' ) ) {
		$wp_customize->add_setting(
			'blog_num',
			array(
				'default' => '3',
				'capability'     	=> 'edit_theme_options',
				'sanitize_callback' => 'ecommerce_comp_sanitize_range_value',
				'priority' => 7,
			)
		);
		$wp_customize->add_control( 
		new Ecommerce_Comp_Customizer_Range_Control( $wp_customize, 'blog_num', 
			array(
				'label'      => __( 'No of Blog Display', 'electromix' ),
				'section'  => 'blog_setting',
				 'media_query'   => false,
					'input_attr'    => array(
						'desktop' => array(
							'min'    => 1,
							'max'    => 500,
							'step'   => 1,
							'default_value' => 3,
						),
					),
			) ) 
		);
	}

}

add_action( 'customize_register', 'electromix_blog_setting' );

// selective refresh
function electromix_blog_section_partials( $wp_customize ){
	
	// blog_ttl
	$wp_customize->selective_refresh->add_partial( 'blog_ttl', array(
		'selector'            => '.post-home .section-title',
		'settings'            => 'blog_ttl',
		'render_callback'  => 'electromix_blog_ttl_render_callback',
	) );
	
	}

add_action( 'customize_register', 'electromix_blog_section_partials' );

// blog2_ttl
function electromix_blog_ttl_render_callback() {
	return get_theme_mod( 'blog_ttl' );
}