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

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

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

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

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

$wp_customize->add_control( 'top_event_theme_options[slider_content_type]',
	array(
		'label'             => esc_html__( 'Content Type', 'top-event' ),
		'section'           => 'top_event_slider_section',
		'type'				=> 'select',
		'active_callback' 	=> 'top_event_is_slider_section_enable',
		'choices'			=> top_event_slider_content_type(),
	)
);

//slider_btn_alt_txt
$wp_customize->add_setting('top_event_theme_options[slider_btn_alt_txt]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'transport'			=> 'postMessage',
        'default'           => $options['slider_btn_alt_txt'],
    )
);

$wp_customize->add_control('top_event_theme_options[slider_btn_alt_txt]',
    array(
        'section'			=> 'top_event_slider_section',
        'label'				=> esc_html__( 'Button Alt Text:', 'top-event' ),
        'type'          	=>'text',
        'active_callback' 	=> 'top_event_is_slider_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[slider_btn_alt_txt]',
		array(
			'selector'            => '#featured-slider-section div.read-more a:nth-child(2)',
			'settings'            => 'top_event_theme_options[slider_btn_alt_txt]',
			'fallback_refresh'    => true,
			'container_inclusive' => false,
			'render_callback'     => 'top_event_slider_btn_alt_txt_partial',
		) 
	);
}

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

	// slider pages drop down chooser control and setting
	$wp_customize->add_setting( 'top_event_theme_options[slider_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[slider_content_page_'. $i .']', 
			array(
				'label'             => sprintf(esc_html__( 'Select Page: %d', 'top-event'), $i ),
				'section'           => 'top_event_slider_section',
				'choices'			=> top_event_page_choices(),
				'active_callback'	=> 'top_event_is_slider_section_content_page_enable',
			)
		)
	);

	if(class_exists('TP_Education')){

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

		$wp_customize->add_control( new Top_Event_Dropdown_Chooser( $wp_customize,
			'top_event_theme_options[slider_content_event_' . $i . ']',
				array(
					'label'             => sprintf( esc_html__( 'Select Event %d', 'top-event' ), $i ),
					'section'           => 'top_event_slider_section',
					'choices'			=> top_event_event_choices(),
					'active_callback'	=> 'top_event_is_slider_section_content_event_enable',
				)
			)
		);

	}

	$wp_customize->add_setting( 'top_event_theme_options[slider_btn_alt_url_'.$i.']',
		array(
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	$wp_customize->add_control( 'top_event_theme_options[slider_btn_alt_url_'.$i.']',
		array(
			'label'             => sprintf(esc_html__( 'Button Alt URL : %d', 'top-event'), $i ),
			'section'        	=> 'top_event_slider_section',
			'active_callback' 	=> 'top_event_is_slider_section_enable',
			'type'				=> 'url',
		) 
	);

	// Top_Event_Customize_Horizontal_Line
    $wp_customize->add_setting('top_event_theme_options[slider_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[slider_separator'. $i .']',
			array(
				'active_callback'       => 'top_event_is_slider_section_enable',
				'type'                  => 'hr',
				'section'               => 'top_event_slider_section',
			)
		)
	);

endfor;


//slider_btn_txt
$wp_customize->add_setting('top_event_theme_options[slider_btn_txt]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'transport'			=> 'postMessage',
        'default'           => $options['slider_btn_txt'],
    )
);

$wp_customize->add_control('top_event_theme_options[slider_btn_txt]',
    array(
        'section'			=> 'top_event_slider_section',
        'label'				=> esc_html__( 'Button Text:', 'top-event' ),
        'type'          	=>'text',
        'active_callback' 	=> 'top_event_is_slider_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[slider_btn_txt]',
		array(
			'selector'            => '#featured-slider-section article div.read-more a:nth-child(1)',
			'settings'            => 'top_event_theme_options[slider_btn_txt]',
			'fallback_refresh'    => true,
			'container_inclusive' => false,
			'render_callback'     => 'top_event_slider_btn_txt_partial',
		) 
	);
}
