<?php
/**
* Slider Section options
*
* @package Theme Palace
* @subpackage Charity Give
* @since Charity Give 1.0.0
*/

// Add Slider section
$wp_customize->add_section( 'charity_give_featured_slider_section', array(
	'title'             => esc_html__( 'Featured Slider','charity-give' ),
	'description'       => esc_html__( 'Featured Slider Section options.', 'charity-give' ),
	'panel'             => 'charity_give_front_page_panel',
	) );

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

$wp_customize->add_control( new Charity_Give_Switch_Control( $wp_customize, 'charity_give_theme_options[featured_slider_section_enable]', array(
	'label'             => esc_html__( 'Featured Slider Section Enable', 'charity-give' ),
	'section'           => 'charity_give_featured_slider_section',
	'on_off_label' 		=> charity_give_switch_options(),
	) ) );

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

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

$wp_customize->add_control( new Charity_Give_Switch_Control( $wp_customize, 'charity_give_theme_options[featured_slider_autoplay]', array(
	'label'             => esc_html__( 'Auto Play Enable', 'charity-give' ),
	'section'           => 'charity_give_featured_slider_section',
	'on_off_label' 		=> charity_give_switch_options(),
	'active_callback' 	=> 'charity_give_is_featured_slider_section_enable',
	) ) );

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

$wp_customize->add_control( 'charity_give_theme_options[featured_slider_btn_text]', array(
	'label'           	=> esc_html__( 'Button Label', 'charity-give' ),
	'section'        	=> 'charity_give_featured_slider_section',
	'active_callback' 	=> 'charity_give_is_featured_slider_section_enable',
	'type'				=> 'text',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'charity_give_theme_options[featured_slider_btn_text]', array(
		'selector'            => '#charity_give_featured_slider_section .read-more .one',
		'settings'            => 'charity_give_theme_options[featured_slider_btn_text]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'charity_give_featured_slider_btn_text_partial',
    ) );
}

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

$wp_customize->add_control( 'charity_give_theme_options[featured_slider_alt_btn_text]', array(
	'label'           	=> esc_html__( 'Alt Button Label', 'charity-give' ),
	'section'        	=> 'charity_give_featured_slider_section',
	'active_callback' 	=> 'charity_give_is_featured_slider_section_enable',
	'type'				=> 'text',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'charity_give_theme_options[featured_slider_alt_btn_text]', array(
		'selector'            => '#charity_give_featured_slider_section .read-more .two',
		'settings'            => 'charity_give_theme_options[featured_slider_alt_btn_text]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'charity_give_featured_slider_alt_btn_text_partial',
    ) );
}

$wp_customize->add_setting( 'charity_give_theme_options[featured_slider_alt_btn_url]', array(
	'sanitize_callback' => 'esc_url_raw',
	'default'			=> $options['featured_slider_alt_btn_url'],
	'transport'			=> 'postMessage',
) );

$wp_customize->add_control( 'charity_give_theme_options[featured_slider_alt_btn_url]', array(
	'label'           	=> esc_html__( 'Alt Button URL', 'charity-give' ),
	'section'        	=> 'charity_give_featured_slider_section',
	'active_callback' 	=> 'charity_give_is_featured_slider_section_enable',
	'type'				=> 'url',
) );


$wp_customize->add_setting( 'charity_give_theme_options[featured_slider_excerpt_length]', array(
	'sanitize_callback' => 'charity_give_sanitize_number_range',
	'validate_callback' => 'charity_give_validate_long_excerpt',
	'default'			=> $options['featured_slider_excerpt_length'],
	) );

$wp_customize->add_control( 'charity_give_theme_options[featured_slider_excerpt_length]', array(
	'label'       		=> esc_html__( 'Excerpt Length', 'charity-give' ),
	'description' 		=> esc_html__( 'Total description words to be displayed in featured slider posts.', 'charity-give' ),
	'section'     		=> 'charity_give_featured_slider_section',
	'active_callback' 	=> 'charity_give_is_featured_slider_section_enable',
	'type'        		=> 'number',
	'input_attrs' 		=> array(
		'style'       => 'width: 80px;',
		'max'         => 100,
		'min'         => 5,
		),
	) );

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

// slider posts drop down chooser control and setting
$wp_customize->add_setting( 'charity_give_theme_options[featured_slider_content_page_' . $i . ']', array(
	'sanitize_callback' => 'charity_give_sanitize_page',
	) );

$wp_customize->add_control( new Charity_Give_Dropdown_Chooser( $wp_customize, 'charity_give_theme_options[featured_slider_content_page_' . $i . ']', array(
	'label'             => sprintf( esc_html__( 'Select Page %d', 'charity-give' ), $i ),
	'section'           => 'charity_give_featured_slider_section',
	'choices'			=> charity_give_page_choices(),
	'active_callback'	=> 'charity_give_is_featured_slider_section_enable',
	) ) );

endfor;