<?php
/**
 * Latest Post Section options
 *
 * @package Theme Palace
 * @subpackage Top Event
 * @since Top Event 1.0.0
 */

// Add Latest Post section
$wp_customize->add_section( 'top_event_latest_post_section',
    array(
        'title'             => esc_html__( 'Latest Post','top-event' ),
        'description'       => esc_html__( 'Latest Post Section options.', 'top-event' ),
        'panel'             => 'top_event_front_page_panel',
    )
);

// Latest Post content enable control and setting
$wp_customize->add_setting( 'top_event_theme_options[latest_post_section_enable]',
    array(
        'default'           =>  $options['latest_post_section_enable'],
        'sanitize_callback' => 'top_event_sanitize_switch_control',
    )
);

$wp_customize->add_control( new Top_Event_Switch_Control( $wp_customize, 'top_event_theme_options[latest_post_section_enable]',
    array(
        'label'             => esc_html__( 'Latest Post Section Enable', 'top-event' ),
        'section'           => 'top_event_latest_post_section',
        'on_off_label'      => top_event_switch_options(),
    ) 
) );

// Latest Post section sub title control and setting
$wp_customize->add_setting('top_event_theme_options[latest_post_sub_title]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
        'default'           => $options['latest_post_sub_title'],
    )
);

$wp_customize->add_control('top_event_theme_options[latest_post_sub_title]',
    array(
        'label'             => esc_html__('Section Sub Title', 'top-event'),
        'section'           => 'top_event_latest_post_section',
        'type'              => 'text',
        'active_callback'   => 'top_event_is_latest_post_section_enable',
    )
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'top_event_theme_options[latest_post_sub_title]',
        array(
            'selector'            => '#latest-posts-section .section-header p.section-subtitle',
            'settings'            => 'top_event_theme_options[latest_post_sub_title]',
            'container_inclusive' => false,
            'fallback_refresh'    => true,
            'render_callback'     => 'top_event_latest_post_sub_title_partial',
        )
    );
}

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

$wp_customize->add_control( 'top_event_theme_options[latest_post_title]',
    array(
        'label'             => esc_html__( 'Section Title', 'top-event' ),
        'section'           => 'top_event_latest_post_section',
        'active_callback'   => 'top_event_is_latest_post_section_enable',
        'type'              => 'text',
    ) 
);

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

// Add dropdown category setting and control.
$wp_customize->add_setting(  'top_event_theme_options[latest_post_content_category]',
    array(
        'sanitize_callback' => 'top_event_sanitize_single_category',
    )
);

$wp_customize->add_control( new Top_Event_Dropdown_Taxonomies_Control( $wp_customize,
    'top_event_theme_options[latest_post_content_category]',
        array(
            'label'             => esc_html__( 'Select Category', 'top-event' ),
            'description'       => esc_html__( 'Note: Latest selected no of posts will be shown from selected category', 'top-event' ),
            'section'           => 'top_event_latest_post_section',
            'type'              => 'dropdown-taxonomies',
            'active_callback'   => 'top_event_is_latest_post_section_enable'
        ) 
    )
);