<?php
/**
 * Testimonial Section options
 *
 * @package Theme Palace
 * @subpackage Ultravel
 * @since Ultravel 1.0.0
 */

// Add Testimonial section
$wp_customize->add_section( 'ultravel_testimonial_section', array(
	'title'             => esc_html__( 'Testimonial','ultravel' ),
	'description'       => esc_html__( 'Testimonial Section options.', 'ultravel' ),
	'panel'             => 'ultravel_front_page_panel',
) );

// Testimonial content enable control and setting
$wp_customize->add_setting( 'ultravel_theme_options[testimonial_section_enable]', array(
	'default'			=> 	$options['testimonial_section_enable'],
	'sanitize_callback' => 'ultravel_sanitize_switch_control',
) );

$wp_customize->add_control( new Ultravel_Switch_Control( $wp_customize, 'ultravel_theme_options[testimonial_section_enable]', array(
	'label'             => esc_html__( 'Testimonial Section Enable', 'ultravel' ),
	'section'           => 'ultravel_testimonial_section',
	'on_off_label' 		=> ultravel_switch_options(),
) ) );

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

// popular destination read more setting and control
$wp_customize->add_setting( 'ultravel_theme_options[testimonial_title]', array(
    'default'           => $options['testimonial_title'],
    'sanitize_callback' => 'sanitize_text_field',
    'transport'         => 'postMessage',
) );

$wp_customize->add_control( 'ultravel_theme_options[testimonial_title]', array(
    'label'             => esc_html__( 'Title', 'ultravel' ),
    'section'           => 'ultravel_testimonial_section',
    'type'              => 'text',
    'active_callback'   => function( $control ) {
    	return (
    		ultravel_is_testimonial_section_enable( $control )
    	);
    },
) );

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


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

$wp_customize->add_control( 'ultravel_theme_options[testimonial_sub_title]', array(
    'label'             => esc_html__( 'Sub Title', 'ultravel' ),
    'section'           => 'ultravel_testimonial_section',
    'type'              => 'text',
    'active_callback'   => function( $control ) {
    	return (
    		ultravel_is_testimonial_section_enable( $control )
    	);
    },
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'ultravel_theme_options[testimonial_sub_title]', array(
        'selector'            => '#ultravel_testimonial_section .section-header p',
        'settings'            => 'ultravel_theme_options[testimonial_sub_title]',
        'container_inclusive' => false,
        'fallback_refresh'    => true,
        'render_callback'     => 'ultravel_testimonial_sub_title_partial',
    ) );
}

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

$wp_customize->add_control( 'ultravel_theme_options[testimonial_content]', array(
    'label'             => esc_html__( 'Content', 'ultravel' ),
    'section'           => 'ultravel_testimonial_section',
    'type'              => 'textarea',
    'active_callback'   => function( $control ) {
    	return (
    		ultravel_is_testimonial_section_enable( $control )
    	);
    },
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'ultravel_theme_options[testimonial_content]', array(
        'selector'            => '#ultravel_testimonial_section .section-content p',
        'settings'            => 'ultravel_theme_options[testimonial_content]',
        'container_inclusive' => false,
        'fallback_refresh'    => true,
        'render_callback'     => 'ultravel_testimonial_content_partial',
    ) );
}

// Testimonial auto play enable control and setting
$wp_customize->add_setting( 'ultravel_theme_options[testimonial_auto_play]', array(
	'default'			=> 	$options['testimonial_auto_play'],
	'sanitize_callback' => 'ultravel_sanitize_switch_control',
) );

$wp_customize->add_control( new Ultravel_Switch_Control( $wp_customize, 'ultravel_theme_options[testimonial_auto_play]', array(
	'label'             => esc_html__( 'Auto Play Enable', 'ultravel' ),
	'section'           => 'ultravel_testimonial_section',
	'on_off_label' 		=> ultravel_switch_options(),
	'active_callback' 	=> 'ultravel_is_testimonial_section_enable',
) ) );

// Event social icons number control and setting
$wp_customize->add_setting( 'ultravel_theme_options[testimonial_count]', array(
	'default'          	=> $options['testimonial_count'],
	'sanitize_callback' => 'ultravel_sanitize_number_range',
	'validate_callback' => 'ultravel_validate_testimonial_count',
) );

$wp_customize->add_control( 'ultravel_theme_options[testimonial_count]', array(
	'label'             => esc_html__( 'Number of Testimonials', 'ultravel' ),
	'description'       => esc_html__( 'Note: Min 1 & Max 99. Please input the valid number and save. Then refresh the page to see the change.', 'ultravel' ),
	'section'           => 'ultravel_testimonial_section',
	'active_callback'   => 'ultravel_is_testimonial_section_enable',
	'type'				=> 'number',
	'input_attrs'		=> array(
		'min'	=> 1,
		'max'	=> 99,
		'style' => 'width: 100px;'
		),
) );

// Testimonial content type control and setting
$wp_customize->add_setting( 'ultravel_theme_options[testimonial_content_type]', array(
	'default'          	=> $options['testimonial_content_type'],
	'sanitize_callback' => 'ultravel_sanitize_select',
) );

$wp_customize->add_control( 'ultravel_theme_options[testimonial_content_type]', array(
	'label'             => esc_html__( 'Content Type', 'ultravel' ),
	'section'           => 'ultravel_testimonial_section',
	'type'				=> 'select',
	'active_callback' 	=> 'ultravel_is_testimonial_section_enable',
	'choices'			=> array( 
		'page' 		=> esc_html__( 'Page', 'ultravel' ),
		'post' 		=> esc_html__( 'Post', 'ultravel' ),
		'category' 	=> esc_html__( 'Category', 'ultravel' ),
		'custom' 	=> esc_html__( 'Custom', 'ultravel' ),
	),
) );

// Add dropdown category setting and control.
$wp_customize->add_setting(  'ultravel_theme_options[testimonial_content_category]', array(
	'sanitize_callback' => 'ultravel_sanitize_single_category',
) ) ;

$wp_customize->add_control( new Ultravel_Dropdown_Taxonomies_Control( $wp_customize,'ultravel_theme_options[testimonial_content_category]', array(
	'label'             => esc_html__( 'Select Category', 'ultravel' ),
	'description'      	=> esc_html__( 'Note: Latest selected no of posts will be shown from selected category', 'ultravel' ),
	'section'           => 'ultravel_testimonial_section',
	'type'              => 'dropdown-taxonomies',
	'active_callback'	=> 'ultravel_is_testimonial_section_content_category_enable'
) ) );

for ( $i = 1; $i <= $options['testimonial_count']; $i++ ) :
	// testimonial pages drop down chooser control and setting
	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_content_page_' . $i . ']', array(
		'sanitize_callback' => 'ultravel_sanitize_page',
	) );

	$wp_customize->add_control( new Ultravel_Dropdown_Chooser( $wp_customize, 'ultravel_theme_options[testimonial_content_page_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Page %d', 'ultravel' ), $i ),
		'section'           => 'ultravel_testimonial_section',
		'choices'			=> ultravel_page_choices(),
		'active_callback'	=> 'ultravel_is_testimonial_section_content_page_enable',
	) ) );

	// testimonial posts drop down chooser control and setting
	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_content_post_' . $i . ']', array(
		'sanitize_callback' => 'ultravel_sanitize_page',
	) );

	$wp_customize->add_control( new Ultravel_Dropdown_Chooser( $wp_customize, 'ultravel_theme_options[testimonial_content_post_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Post %d', 'ultravel' ), $i ),
		'section'           => 'ultravel_testimonial_section',
		'choices'			=> ultravel_post_choices(),
		'active_callback'	=> 'ultravel_is_testimonial_section_content_post_enable',
	) ) );

	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_position_' . $i . ']', array(
		'sanitize_callback' => 'sanitize_text_field',
	) );

	$wp_customize->add_control( 'ultravel_theme_options[testimonial_position_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'Position %d', 'ultravel' ), $i ),
		'section'        	=> 'ultravel_testimonial_section',
		'active_callback' 	=> 'ultravel_is_testimonial_section_enable',
		'type'				=> 'text',
	) );


	// testimonial title setting and control
	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_title_' . $i . ']', array(
		'sanitize_callback' => 'sanitize_text_field',
	) );

	$wp_customize->add_control( 'ultravel_theme_options[testimonial_title_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'Title %d', 'ultravel' ), $i ),
		'section'        	=> 'ultravel_testimonial_section',
		'active_callback' 	=> 'ultravel_is_testimonial_section_content_custom_enable',
		'type'				=> 'text',
	) );

	// testimonial description setting and control
	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_description_' . $i . ']', array(
		'sanitize_callback' => 'wp_kses_post',
	) );

	$wp_customize->add_control( 'ultravel_theme_options[testimonial_description_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'Description %d', 'ultravel' ), $i ),
		'section'        	=> 'ultravel_testimonial_section',
		'active_callback' 	=> 'ultravel_is_testimonial_section_content_custom_enable',
		'type'				=> 'textarea',
	) );

	// testimonial image setting and control.
	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_image_' . $i . ']', array(
		'sanitize_callback' => 'ultravel_sanitize_image'
	) );

	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'ultravel_theme_options[testimonial_image_' . $i . ']',
			array(
			'label'       		=> sprintf( esc_html__( 'Image %d', 'ultravel' ), $i ),
			'description' 		=> sprintf( esc_html__( 'Recommended size: %1$dpx x %2$dpx ', 'ultravel' ), 700, 600 ),
			'section'     		=> 'ultravel_testimonial_section',
			'active_callback'	=> 'ultravel_is_testimonial_section_content_custom_enable',
	) ) );

	// testimonial link setting and control
	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_link_' . $i . ']', array(
		'sanitize_callback' => 'esc_url_raw',
	) );

	$wp_customize->add_control( 'ultravel_theme_options[testimonial_link_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'URL Link %d', 'ultravel' ), $i ),
		'section'        	=> 'ultravel_testimonial_section',
		'active_callback' 	=> 'ultravel_is_testimonial_section_content_custom_enable',
		'type'				=> 'url',
	) );

	// testimonial hr setting and control
	$wp_customize->add_setting( 'ultravel_theme_options[testimonial_hr_'. $i .']', array(
		'sanitize_callback' => 'sanitize_text_field'
	) );

	$wp_customize->add_control( new Ultravel_Customize_Horizontal_Line( $wp_customize, 'ultravel_theme_options[testimonial_hr_'. $i .']',
		array(
			'section'         => 'ultravel_testimonial_section',
			'active_callback' => 'ultravel_is_testimonial_section_content_author_enable',
			'type'			  => 'hr'
	) ) );
endfor;

