<?php
function flossy_blog_setting( $wp_customize ) {
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
$wp_customize->add_panel(
		'flossy_frontpage_sections', array(
			'priority' => 32,
			'title' => esc_html__( 'Frontpage Sections', 'flossy' ),
		)
	);
	/*=========================================
	Blog Section
	=========================================*/
	$wp_customize->add_section(
		'blog_setting', array(
			'title' => esc_html__( 'Blog Section', 'flossy' ),
			'priority' => 8,
			'panel' => 'flossy_frontpage_sections',
		)
	);
	
	/*=========================================
	Header
	=========================================*/
	$wp_customize->add_setting(
		'blog_header'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'flossy_sanitize_text',
			'priority' => 1,
		)
	);

	$wp_customize->add_control(
	'blog_header',
		array(
			'type' => 'hidden',
			'label' => __('Header','flossy'),
			'section' => 'blog_setting',
		)
	);
	
	//  Title // 
	$wp_customize->add_setting(
    	'blog_ttl',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'flossy_sanitize_html',
			'transport'         => $selective_refresh,
			'priority' => 2,
		)
	);	
	
	$wp_customize->add_control( 
		'blog_ttl',
		array(
		    'label'   => __('Title','flossy'),
		    'section' => 'blog_setting',
			'type'           => 'text',
		)  
	);
	
	/*=========================================
	Content
	=========================================*/
	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
	if(is_plugin_active('ecommerce-companion/ecommerce-companion.php')){
		$wp_customize->add_setting(
			'blog_content'
				,array(
				'capability'     	=> 'edit_theme_options',
				'sanitize_callback' => 'flossy_sanitize_text',
				'priority' => 5,
			)
		);

		$wp_customize->add_control(
		'blog_content',
			array(
				'type' => 'hidden',
				'label' => __('Content','flossy'),
				'section' => 'blog_setting',
			)
		);
		
		// No. of Products Display
		if ( class_exists( 'Ecommerce_Comp_Customizer_Range_Control' ) ) {
			$wp_customize->add_setting(
				'blog_num',
				array(
					'default' => '6',
					'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', 'flossy' ),
					'section'  => 'blog_setting',
					 'media_query'   => false,
						'input_attr'    => array(
							'desktop' => array(
								'min'    => 1,
								'max'    => 500,
								'step'   => 1,
								'default_value' => 6,
							),
						),
				) ) 
			);
		}
	}	

}

add_action( 'customize_register', 'flossy_blog_setting' );

// selective refresh
function flossy_blog_section_partials( $wp_customize ){
	
	// blog_ttl
	$wp_customize->selective_refresh->add_partial( 'blog_ttl', array(
		'selector'            => '.blog-home .section-title-name',
		'settings'            => 'blog_ttl',
		'render_callback'  => 'flossy_blog_ttl_render_callback',
	) );
	
	}

add_action( 'customize_register', 'flossy_blog_section_partials' );

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