<?php
/**
 * Popular Posts Section options
 *
 * @package Theme Palace
 * @subpackage Ultravel
 * @since Ultravel 1.0.0
 */

// Add Popular Posts section
$wp_customize->add_section( 'ultravel_popular_posts_section', array(
	'title'             => esc_html__( 'Popular Posts','ultravel' ),
	'description'       => esc_html__( 'Popular Posts Section options.', 'ultravel' ),
	'panel'             => 'ultravel_front_page_panel',
) );

// Popular Posts content enable control and setting
$wp_customize->add_setting( 'ultravel_theme_options[popular_posts_section_enable]', array(
	'default'			=> 	$options['popular_posts_section_enable'],
	'sanitize_callback' => 'ultravel_sanitize_switch_control',
) );

$wp_customize->add_control( new Ultravel_Switch_Control( $wp_customize, 'ultravel_theme_options[popular_posts_section_enable]', array(
	'label'             => esc_html__( 'Popular Posts Section Enable', 'ultravel' ),
	'section'           => 'ultravel_popular_posts_section',
	'on_off_label' 		=> ultravel_switch_options(),
) ) );

if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'ultravel_theme_options[popular_posts_section_enable]', array(
        'selector'      => '#ultravel_popular_posts_section .tooltiptext',
        'settings'      => 'ultravel_theme_options[popular_posts_section_enable]',
    ) );
}

// Popular Posts title setting and control
$wp_customize->add_setting( 'ultravel_theme_options[popular_posts_title]', array(
	'sanitize_callback' => 'sanitize_text_field',
	'default'			=> $options['popular_posts_title'],
	'transport'			=> 'postMessage',
) );

$wp_customize->add_control( 'ultravel_theme_options[popular_posts_title]', array(
	'label'           	=> esc_html__( 'Title', 'ultravel' ),
	'section'        	=> 'ultravel_popular_posts_section',
	'active_callback' 	=> 'ultravel_is_popular_posts_section_enable',
	'type'				=> 'text',
) );

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

// Popular Posts title setting and control
$wp_customize->add_setting( 'ultravel_theme_options[popular_posts_sub_title]', array(
	'sanitize_callback' => 'sanitize_text_field',
	'default'			=> $options['popular_posts_sub_title'],
	'transport'			=> 'postMessage',
) );

$wp_customize->add_control( 'ultravel_theme_options[popular_posts_sub_title]', array(
	'label'           	=> esc_html__( 'Sub Title', 'ultravel' ),
	'section'        	=> 'ultravel_popular_posts_section',
	'active_callback' 	=> 'ultravel_is_popular_posts_section_enable',
	'type'				=> 'text',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'ultravel_theme_options[popular_posts_sub_title]', array(
		'selector'            => '#ultravel_popular_posts_section .section-header p',
		'settings'            => 'ultravel_theme_options[popular_posts_sub_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'ultravel_popular_posts_section_sub_title_partial',
    ) );
}

// Popular Posts content type control and setting
$wp_customize->add_setting( 'ultravel_theme_options[popular_posts_content_type]', array(
	'default'          	=> $options['popular_posts_content_type'],
	'sanitize_callback' => 'ultravel_sanitize_select',
) );

$wp_customize->add_control( 'ultravel_theme_options[popular_posts_content_type]', array(
	'label'             => esc_html__( 'Content Type', 'ultravel' ),
	'section'           => 'ultravel_popular_posts_section',
	'type'				=> 'select',
	'active_callback' 	=> 'ultravel_is_popular_posts_section_enable',
	'choices'			=> ultravel_popular_posts_section_content_type(),
) );

for ( $i = 1; $i <= 4; $i++ ) :
	// Popular Posts pages drop down chooser control and setting
	$wp_customize->add_setting( 'ultravel_theme_options[popular_posts_content_page_' . $i . ']', array(
		'sanitize_callback' => 'ultravel_sanitize_page',
	) );

	$wp_customize->add_control( new Ultravel_Dropdown_Chooser( $wp_customize, 'ultravel_theme_options[popular_posts_content_page_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Page %d', 'ultravel' ), $i ),
		'section'           => 'ultravel_popular_posts_section',
		'choices'			=> ultravel_page_choices(),
		'active_callback'	=> 'ultravel_is_popular_posts_section_content_page_enable',
	) ) );

	// Popular Posts posts drop down chooser control and setting
	$wp_customize->add_setting( 'ultravel_theme_options[popular_posts_content_post_' . $i . ']', array(
		'sanitize_callback' => 'ultravel_sanitize_page',
	) );

	$wp_customize->add_control( new Ultravel_Dropdown_Chooser( $wp_customize, 'ultravel_theme_options[popular_posts_content_post_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Post %d', 'ultravel' ), $i ),
		'section'           => 'ultravel_popular_posts_section',
		'choices'			=> ultravel_post_choices(),
		'active_callback'	=> 'ultravel_is_popular_posts_section_content_post_enable',
	) ) );

endfor;

// Add dropdown category setting and control.
$wp_customize->add_setting(  'ultravel_theme_options[popular_posts_content_category]', array(
	'sanitize_callback' => 'ultravel_sanitize_single_category',
) ) ;

$wp_customize->add_control( new Ultravel_Dropdown_Taxonomies_Control( $wp_customize,'ultravel_theme_options[popular_posts_content_category]', array(
	'label'             => esc_html__( 'Select Category', 'ultravel' ),
	'description'      	=> esc_html__( 'Note: Latest selected no of posts will be shown from selected category', 'ultravel' ),
	'section'           => 'ultravel_popular_posts_section',
	'type'              => 'dropdown-taxonomies',
	'active_callback'	=> 'ultravel_is_popular_posts_section_content_category_enable'
) ) );