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

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

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

$wp_customize->add_control( new  Top_Event_Switch_Control( $wp_customize,
	'top_event_theme_options[event_section_enable]',
		array(
			'label'             => esc_html__( 'Event Section Enable', 'top-event' ),
			'section'           => 'top_event_event_section',
			'on_off_label' 		=> top_event_switch_options(),
		)
	)
);

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

$wp_customize->add_control('top_event_theme_options[event_sub_title]',
    array(
        'label'             => esc_html__('Section Sub Title', 'top-event'),
        'section'           => 'top_event_event_section',
        'type'              => 'text',
        'active_callback'   => 'top_event_is_event_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[event_sub_title]',
        array(
            'selector'            => '#events-section .section-header p.section-subtitle',
            'settings'            => 'top_event_theme_options[event_sub_title]',
            'container_inclusive' => false,
            'fallback_refresh'    => true,
            'render_callback'     => 'top_event_event_sub_title_partial',
        )
    );
}

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

$wp_customize->add_control( 'top_event_theme_options[event_title]',
    array(
        'label'             => esc_html__( 'Section Title', 'top-event' ),
        'section'           => 'top_event_event_section',
        'active_callback'   => 'top_event_is_event_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[event_title]',
        array(
            'selector'            => '#events-section .section-header h2.section-title',
            'settings'            => 'top_event_theme_options[event_title]',
            'container_inclusive' => false,
            'fallback_refresh'    => true,
            'render_callback'     => 'top_event_event_title_partial',
        )
    );
}

// Event content type control and setting
$wp_customize->add_setting( 'top_event_theme_options[event_content_type]',
	array(
		'default'          	=> $options['event_content_type'],
		'sanitize_callback' => 'top_event_sanitize_select',
	)
);

$wp_customize->add_control( 'top_event_theme_options[event_content_type]',
	array(
		'label'             => esc_html__( 'Content Type', 'top-event' ),
		'section'           => 'top_event_event_section',
		'type'				=> 'select',
		'active_callback' 	=> 'top_event_is_event_section_enable',
		'choices'			=> top_event_event_content_type(),
	)
);


for ( $i = 1; $i <= $options['event_count']; $i++ ) :

	// slider pages drop down chooser control and setting
	$wp_customize->add_setting( 'top_event_theme_options[event_content_page_'. $i .']', 
		array(
			'sanitize_callback' => 'top_event_sanitize_page',
		)
	);

	$wp_customize->add_control( new  Top_Event_Dropdown_Chooser( $wp_customize,
		'top_event_theme_options[event_content_page_'. $i .']', 
			array(
				'label'             => sprintf(esc_html__( 'Select Page: %d', 'top-event'), $i ),
				'section'           => 'top_event_event_section',
				'choices'			=> top_event_page_choices(),
				'active_callback'	=> 'top_event_is_event_section_content_page_enable',
			)
		)
	);

	// Top_Event_Customize_Horizontal_Line
    $wp_customize->add_setting('top_event_theme_options[event_separator'. $i .']',
		array(
			'sanitize_callback'      => 'top_event_sanitize_html',
		)
	);

    $wp_customize->add_control(new Top_Event_Customize_Horizontal_Line($wp_customize,
		'top_event_theme_options[event_separator'. $i .']',
			array(
				'active_callback'       => 'top_event_is_event_section_separator_enable',
				'type'                  =>'hr',
				'section'               =>'top_event_event_section',
			)
		)
	);

endfor;

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

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

