<?php
function storex_blog_settings( $wp_customize ) {
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	/*=========================================
	Frontpage Panel
	=========================================*/
	$wp_customize->add_panel(
		'storex_frontpage_sections', array(
			'priority' => 32,
			'title' => esc_html__( 'Frontpage Sections', 'storex' ),
		)
	);
	
	/*=========================================
	Blog Section
	=========================================*/
	$wp_customize->add_section(
		'storex_blog_setting', array(
			'title' => esc_html__( 'Blog Section', 'storex' ),
			'priority' => 20,
			'panel' => 'storex_frontpage_sections',
		)
	);
	
	// Blog Settings Section // 
	
	$wp_customize->add_setting(
		'storex_blog_setting_head'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_text',
			'priority' => 5,
		)
	);

	$wp_customize->add_control(
	'storex_blog_setting_head',
		array(
			'type' => 'hidden',
			'label' => __('Settings','storex'),
			'section' => 'storex_blog_setting',
		)
	);
	// hide/show
	$wp_customize->add_setting( 
		'storex_hs_blog' , 
			array(
			'default'    => esc_html__( '1', 'storex' ),
			'capability' => 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_checkbox',
			'priority' => 6,
		) 
	);
	
	$wp_customize->add_control(
	'storex_hs_blog', 
		array(
			'label'	      => esc_html__( 'Hide/Show', 'storex' ),
			'section'     => 'storex_blog_setting',
			'type'        => 'checkbox',
		) 
	);	
	
	// Blog Header Section // 
	$wp_customize->add_setting(
		'storex_blog_headings'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_text',
			'priority' => 3,
		)
	);

	$wp_customize->add_control(
	'storex_blog_headings',
		array(
			'type' => 'hidden',
			'label' => __('Header','storex'),
			'section' => 'storex_blog_setting',
		)
	);
	
	// Blog Title // 
	$wp_customize->add_setting(
    	'storex_blog_title',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_html',
			'transport'         => $selective_refresh,
			'priority' => 4,
		)
	);	
	
	$wp_customize->add_control( 
		'storex_blog_title',
		array(
		    'label'   => __('Title','storex'),
		    'section' => 'storex_blog_setting',
			'type'           => 'text',
		)  
	);
     // View All News // 
	$wp_customize->add_setting(
		'storex_blog_view_all_label',
		array(
			'sanitize_callback' => 'storex_sanitize_text',
			'transport'         => $selective_refresh,
			'capability' => 'edit_theme_options',
			'priority' => 5,
		)
	);	

	$wp_customize->add_control( 
		'storex_blog_view_all_label',
		array(
			'label'   		=> __('Label','storex'),
			'section' 		=> 'storex_blog_setting',
			'type'		 =>	'text',
		)  
	);

	// View All News Link // 
	$wp_customize->add_setting(
		'storex_blog_view_all_url',
		array(
			'default'			=> '',
			'sanitize_callback' => 'storex_sanitize_url',
			'transport'         => $selective_refresh,
			'capability' => 'edit_theme_options',
			'priority' => 6,
		)
	);	
	$wp_customize->add_control( 
		'storex_blog_view_all_url',
		array(
			'label'   		=> __('Link','storex'),
			'section' 		=> 'storex_blog_setting',
			'type'		 =>	'text'
		)  
	);	

	// Blog content Section // 
	$wp_customize->add_setting(
		'storex_blog_content_head'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_text',
			'priority' => 7,
		)
	);

	$wp_customize->add_control(
	'storex_blog_content_head',
		array(
			'type' => 'hidden',
			'label' => __('Content','storex'),
			'section' => 'storex_blog_setting',
		)
	);
	
	// storex_blog_display_num
	if ( class_exists( 'Burger_Customizer_Range_Control' ) ) {
		$wp_customize->add_setting(
			'storex_blog_display_num',
			array(
				'default'    => esc_html__( '3', 'storex' ),
				'capability'     	=> 'edit_theme_options',
				'sanitize_callback' => 'storex_sanitize_range_value',
				'priority' => 8,
			)
		);
		$wp_customize->add_control( 
		new Burger_Customizer_Range_Control( $wp_customize, 'storex_blog_display_num', 
			array(
				'label'      => __( 'No of Posts Display', 'storex' ),
				'section'  => 'storex_blog_setting',
				 'input_attrs' => array(
					'min'    => 1,
					'max'    => 100,
					'step'   => 1,
					//'suffix' => 'px', //optional suffix
				),
			) ) 
		);
	}
	
}

add_action( 'customize_register', 'storex_blog_settings' );

// blog selective refresh
function storex_blog_section_partials( $wp_customize ){	
	// blog_title
	$wp_customize->selective_refresh->add_partial( 'blog_title', array(
		'selector'            => '.news-section .large-container .sec-title h2',
		'settings'            => 'blog_title',
		'render_callback'  => 'storex_blog_title_render_callback',
	) );	
	}

add_action( 'customize_register', 'storex_blog_section_partials' );

// blog_title
function storex_blog_title_render_callback() {
	return get_theme_mod( 'blog_title' );
}
