<?php
function news25_blog_setting( $wp_customize ) {
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	/*=========================================
	Blog  Section
	=========================================*/
	$wp_customize->add_section(
		'blog_setting', array(
			'title' => esc_html__( 'Blog Section', 'news-25' ),
			'priority' => 10,
			'panel' => 'news25_frontpage_sections',
		)
	);

	// Blog Header Section // 
	$wp_customize->add_setting(
		'blog_headings'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'news25_sanitize_text',
			'priority' => 3,
		)
	);

	$wp_customize->add_control(
	'blog_headings',
	array(
			'type' => 'hidden',
			'label' => __('Header','news-25'),
			'section' => 'blog_setting',
		)
	);
	
	// Blog Title // 
	$wp_customize->add_setting(
    	'blog_title',
    	array(
	        'default'			=> 'Recent',
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'news25_sanitize_html',
			// 'transport'         => $selective_refresh,
			'priority' => 4,
		)
	);	
	
	$wp_customize->add_control( 
		'blog_title',
		array(
		    'label'   => __('Title','news-25'),
		    'section' => 'blog_setting',
			'type'           => 'text',
		)  
	);
	
	// Blog Description // 
	$wp_customize->add_setting(
    	'blog_subtitle',
    	array(
	        'default'			=> __('Post','news-25'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'news25_sanitize_text',
			// 'transport'         => $selective_refresh,
			'priority' => 6,
		)
	);	
	
	$wp_customize->add_control( 
		'blog_subtitle',
		array(
		    'label'   => __('Subtitle','news-25'),
		    'section' => 'blog_setting',
			'type'           => 'text',
		)  
	);

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

	$wp_customize->add_control(
	'blog_content_head',
		array(
			'type' => 'hidden',
			'label' => __('Content','news-25'),
			'section' => 'blog_setting',
		)
	);
	
	// Blog Category
	$wp_customize->add_setting(
    'blog_category_id',
		array(
		'capability' => 'edit_theme_options',
		'default' => 1,
		'priority' => 8,
		'sanitize_callback' => 'sanitize_categories'
		)
	);	
	$wp_customize->add_control( new News25_Category_Dropdown_Custom_Control( $wp_customize, 
	'blog_category_id', 
		array(
		'label'   => __('Select Categories','news-25'),
		'section' => 'blog_setting',
		) 
	) );
	
	// blog_display_num
	if ( function_exists('cleverfox_activate') && class_exists( 'Cleverfox_Customizer_Range_Slider_Control' ) ) {
		$wp_customize->add_setting(
			'blog_display_num',
			array(
				'default' => '5',
				'capability'     	=> 'edit_theme_options',
				'sanitize_callback' => 'news25_sanitize_range_value',
				'priority' => 8,
			)
		);
		$wp_customize->add_control( 
		new Cleverfox_Customizer_Range_Slider_Control( $wp_customize, 'blog_display_num', 
			array(
				'label'      => __( 'No of Posts Display', 'news-25' ),
				'section'  => 'blog_setting',
				 'media_query'   => false,
					'input_attr'    => array(
						'desktop' => array(
							'min'    => 1,
							'max'    => 500,
							'step'   => 1,
							'default_value' => 5,
						),
					),
			) ) 
		);
	}
	
	$wp_customize->add_setting(
		'date_visibility'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'news25_sanitize_text',
			'priority' => 7,
		)
	);

	$wp_customize->add_control(
	'date_visibility',
		array(
			'type' => 'hidden',
			'label' => __('Date Show Hide','news-25'),
			'section' => 'blog_setting',
		)
	);
	
	$wp_customize->add_setting( 
		'hs_home_blog_date' , 
			array(
			'capability' => 'edit_theme_options',
			'sanitize_callback' => 'news25_sanitize_checkbox',
			'default' => '1'
		) 
	);

	$wp_customize->add_control(
	'hs_home_blog_date', 
		array(
			'label'	      => esc_html__( 'Hide/Show', 'news-25' ),
			'section'     => 'blog_setting',
			'type'        => 'checkbox'
		) 
	);
	
	$wp_customize->add_setting(
		'author_visibility'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'news25_sanitize_text',
			'priority' => 7,
		)
	);

	$wp_customize->add_control(
	'author_visibility',
		array(
			'type' => 'hidden',
			'label' => __('Author Show Hide','news-25'),
			'section' => 'blog_setting',
		)
	);
	
	$wp_customize->add_setting( 
		'hs_home_blog_author' , 
			array(
			'capability' => 'edit_theme_options',
			'sanitize_callback' => 'news25_sanitize_checkbox',
			'default' => '1'
		) 
	);

	$wp_customize->add_control(
	'hs_home_blog_author', 
		array(
			'label'	      => esc_html__( 'Hide/Show', 'news-25' ),
			'section'     => 'blog_setting',
			'type'        => 'checkbox'
		) 
	);
}

add_action( 'customize_register', 'news25_blog_setting' );

// blog selective refresh
function news25_home_blog_section_partials( $wp_customize ){	
	// blog title
	$wp_customize->selective_refresh->add_partial( 'blog_title', array(
		'selector'            => '.blog-home .heading-default h1',
		'settings'            => 'blog_title',
		'render_callback'  => 'news25_blog_title_render_callback',
	
	) );
	
	// blog description
	$wp_customize->selective_refresh->add_partial( 'blog_description', array(
		'selector'            => '.blog-home .heading-default p',
		'settings'            => 'blog_description',
		'render_callback'  => 'news25_blog_desc_render_callback',
	
	) );
	
	}

add_action( 'customize_register', 'news25_home_blog_section_partials' );

// blog title
function news25_blog_title_render_callback() {
	return get_theme_mod( 'blog_title' );
}

// blog description
function news25_blog_desc_render_callback() {
	return get_theme_mod( 'blog_description' );
}