<?php
/**
 * Featured Posts options
 *
 * @package Theme Palace
 * @subpackage Pushpa
 * @since Pushpa 1.0.0
 */

// Add Featured Posts
$wp_customize->add_section( 'pushpa_featured_posts_section', array(
	'title'             => esc_html__( 'Featured Posts','pushpa' ),
	'description'       => esc_html__( 'Featured Posts options.', 'pushpa' ),
	'panel'             => 'pushpa_front_page_panel',
	) );

// Hero content enable control and setting
$wp_customize->add_setting( 'pushpa_theme_options[featured_posts_section_enable]', array(
	'default'			=> 	$options['featured_posts_section_enable'],
	'sanitize_callback' => 'pushpa_sanitize_switch_control',
	) );

$wp_customize->add_control( new Pushpa_Switch_Control( $wp_customize, 'pushpa_theme_options[featured_posts_section_enable]', array(
	'label'             => esc_html__( 'Featured Posts Enable', 'pushpa' ),
	'section'           => 'pushpa_featured_posts_section',
	'on_off_label' 		=> pushpa_switch_options(),
	) ) );

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

// latest_post title setting and control
$wp_customize->add_setting( 'pushpa_theme_options[featured_posts_title]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'default'           => $options['featured_posts_title'],
        'transport'         => 'postMessage',
    )
);

$wp_customize->add_control( 'pushpa_theme_options[featured_posts_title]',
    array(
        'label'             => esc_html__( 'Section Title', 'pushpa' ),
        'section'           => 'pushpa_featured_posts_section',
        'active_callback'   => 'pushpa_is_featured_posts_section_enable',
        'type'              => 'text',
    )
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'pushpa_theme_options[featured_posts_title]',
        array(
            'selector'            => '#pushpa_featured_posts div.section-header h2',
            'settings'            => 'pushpa_theme_options[featured_posts_title]',
            'container_inclusive' => false,
            'fallback_refresh'    => true,
            'render_callback'     => 'pushpa_featured_posts_title_partial',
        )
    );
}

for ( $i = 1; $i <= 5; $i++ ) :

// hero posts drop down chooser control and setting
$wp_customize->add_setting( 'pushpa_theme_options[featured_posts_content_post_' . $i . ']', array(
	'sanitize_callback' => 'pushpa_sanitize_page',
	) );

$wp_customize->add_control( new Pushpa_Dropdown_Chooser( $wp_customize, 'pushpa_theme_options[featured_posts_content_post_' . $i . ']', array(
	'label'             => sprintf( esc_html__( 'Select Post %d', 'pushpa' ), $i ),
	'section'           => 'pushpa_featured_posts_section',
	'choices'			=> pushpa_post_choices(),
	'active_callback'	=> 'pushpa_is_featured_posts_section_enable',
	) ) );
endfor;