<?php
/**
 * Latest Blog Section options
 *
 * @package Theme Palace
 * @subpackage Kompany
 * @since Kompany 1.0.0
 */

// Add Latest Blog section
$wp_customize->add_section( 'kompany_latest_blog_section', array(
	'title'             => esc_html__( 'Latest Blog','kompany' ),
	'description'       => esc_html__( 'Latest Blog Section options.', 'kompany' ),
	'panel'             => 'kompany_front_page_panel',
) );

// Latest Blog content enable control and setting
$wp_customize->add_setting( 'kompany_theme_options[latest_blog_section_enable]', array(
	'default'			=> 	$options['latest_blog_section_enable'],
	'sanitize_callback' => 'kompany_sanitize_switch_control',
) );

$wp_customize->add_control( new Kompany_Switch_Control( $wp_customize, 'kompany_theme_options[latest_blog_section_enable]', array(
	'label'             => esc_html__( 'Latest Blog Section Enable', 'kompany' ),
	'section'           => 'kompany_latest_blog_section',
	'on_off_label' 		=> kompany_switch_options(),
) ) );

// Latest Blog btn label setting and control
$wp_customize->add_setting( 'kompany_theme_options[latest_blog_title]', array(
	'sanitize_callback' => 'sanitize_text_field',
	'default'			=> $options['latest_blog_title'],
	'transport'			=> 'postMessage',
) );

$wp_customize->add_control( 'kompany_theme_options[latest_blog_title]', array(
	'label'           	=> esc_html__( 'Section Title', 'kompany' ),
	'section'        	=> 'kompany_latest_blog_section',
	'active_callback' 	=> 'kompany_is_latest_blog_section_enable',
	'type'				=> 'text',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'kompany_theme_options[latest_blog_title]', array(
		'selector'            => '#kompany_latest_blog_section h2.section-title',
		'settings'            => 'kompany_theme_options[latest_blog_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'kompany_latest_blog_title_partial',
    ) );
}

// Latest Blog content type control and setting
$wp_customize->add_setting( 'kompany_theme_options[latest_blog_content_type]', array(
	'default'          	=> $options['latest_blog_content_type'],
	'sanitize_callback' => 'kompany_sanitize_select',
) );

$wp_customize->add_control( 'kompany_theme_options[latest_blog_content_type]', array(
	'label'             => esc_html__( 'Content Type', 'kompany' ),
	'section'           => 'kompany_latest_blog_section',
	'type'				=> 'select',
	'active_callback' 	=> 'kompany_is_latest_blog_section_enable',
	'choices'			=> array(
		'post'      => esc_html__( 'Post', 'kompany' ),
		'category'  => esc_html__( 'Category', 'kompany' ),
		),
) );

for ( $i = 1; $i <= 3; $i++ ) :
	
	// latest_blog posts drop down chooser control and setting
	$wp_customize->add_setting( 'kompany_theme_options[latest_blog_content_post_' . $i . ']', array(
		'sanitize_callback' => 'kompany_sanitize_page',
	) );

	$wp_customize->add_control( new Kompany_Dropdown_Chooser( $wp_customize, 'kompany_theme_options[latest_blog_content_post_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Post %d', 'kompany' ), $i ),
		'section'           => 'kompany_latest_blog_section',
		'choices'			=> kompany_post_choices(),
		'active_callback'	=> 'kompany_is_latest_blog_section_content_post_enable',
	) ) );

endfor;

// Add dropdown category setting and control.
$wp_customize->add_setting(  'kompany_theme_options[latest_blog_content_category]', array(
	'sanitize_callback' => 'kompany_sanitize_single_category',
) ) ;

$wp_customize->add_control( new Kompany_Dropdown_Taxonomies_Control( $wp_customize,'kompany_theme_options[latest_blog_content_category]', array(
	'label'             => esc_html__( 'Select Category', 'kompany' ),
	'description'      	=> esc_html__( 'Note: Latest selected no of posts will be shown from selected category', 'kompany' ),
	'section'           => 'kompany_latest_blog_section',
	'type'              => 'dropdown-taxonomies',
	'active_callback'	=> 'kompany_is_latest_blog_section_content_category_enable'
) ) );