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

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

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

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

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

$wp_customize->add_control( 'ultravel_theme_options[about_sub_title]', array(
	'label'           	=> esc_html__( 'Sub Title', 'ultravel' ),
	'section'        	=> 'ultravel_about_section',
	'active_callback' 	=> 'ultravel_is_about_section_enable',
	'type'				=> 'text',
) );

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

// about pages drop down chooser control and setting
$wp_customize->add_setting( 'ultravel_theme_options[about_content_page]', array(
	'sanitize_callback' => 'ultravel_sanitize_page',
) );

$wp_customize->add_control( new Ultravel_Dropdown_Chooser( $wp_customize, 'ultravel_theme_options[about_content_page]', array(
	'label'             => esc_html__( 'Select Page', 'ultravel' ),
	'section'           => 'ultravel_about_section',
	'choices'			=> ultravel_page_choices(),
	'active_callback'	=> 'ultravel_is_about_section_enable',
) ) );

// about btn title setting and control
$wp_customize->add_setting( 'ultravel_theme_options[about_btn_title]', array(
	'sanitize_callback' => 'sanitize_text_field',
	'default'			=> $options['about_btn_title'],
	'transport'			=> 'postMessage',
) );

$wp_customize->add_control( 'ultravel_theme_options[about_btn_title]', array(
	'label'           	=> esc_html__( 'Button Label', 'ultravel' ),
	'section'        	=> 'ultravel_about_section',
	'active_callback' 	=> 'ultravel_is_about_section_enable',
	'type'				=> 'text',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'ultravel_theme_options[about_btn_title]', array(
		'selector'            => '#ultravel_about_section .read-more a',
		'settings'            => 'ultravel_theme_options[about_btn_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'ultravel_about_btn_title_partial',
    ) );
}


// counter hr setting and control
$wp_customize->add_setting( 'ultravel_theme_options[counter_hr]', array(
	'sanitize_callback' => 'sanitize_text_field'
) );

$wp_customize->add_control( new Ultravel_Customize_Horizontal_Line( $wp_customize, 'ultravel_theme_options[counter_hr]',
	array(
		'section'         => 'ultravel_about_section',
		'active_callback' => 'ultravel_is_about_section_enable',
		'type'			  => 'hr'
	) ) );

$wp_customize->add_setting( 'ultravel_theme_options[counter_bg_image]',
	array(
		'sanitize_callback' => 'ultravel_sanitize_image',
	)
);

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize,
	'ultravel_theme_options[counter_bg_image]',
		array(
			'label'       		=> esc_html__( 'Featured Image', 'ultravel' ),
			'description' 		=> sprintf( esc_html__( 'Recommended size: %1$dpx x %2$dpx ', 'ultravel' ), 550, 521 ),
			'section'     		=> 'ultravel_about_section',
			'active_callback'	=> 'ultravel_is_about_section_enable',
		)
	)
);


for ( $i = 1; $i <= 2; $i++ ) :
	$wp_customize->add_setting( 'ultravel_theme_options[about_counter_count_'.$i.']', array(
		'sanitize_callback' => 'sanitize_text_field',
	) );

	$wp_customize->add_control( 'ultravel_theme_options[about_counter_count_'.$i.']', array(
		'label'           	=> esc_html__( 'Counter Count ', 'ultravel' ).$i,
		'section'        	=> 'ultravel_about_section',
		'active_callback' 	=> 'ultravel_is_about_section_enable',
		'type'				=> 'text',
	) );

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

	$wp_customize->add_control( 'ultravel_theme_options[about_counter_label_'.$i.']', array(
		'label'           	=> esc_html__( 'Counter Label ', 'ultravel' ).$i,
		'section'        	=> 'ultravel_about_section',
		'active_callback' 	=> 'ultravel_is_about_section_enable',
		'type'				=> 'text',
	) );

endfor;

// services hr setting and control
$wp_customize->add_setting( 'ultravel_theme_options[services_hr]', array(
	'sanitize_callback' => 'sanitize_text_field'
) );

$wp_customize->add_control( new Ultravel_Customize_Horizontal_Line( $wp_customize, 'ultravel_theme_options[services_hr]',
	array(
		'section'         => 'ultravel_about_section',
		'active_callback' => 'ultravel_is_about_section_enable',
		'type'			  => 'hr'
	) ) );

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

$wp_customize->add_control( new Ultravel_Switch_Control( $wp_customize, 'ultravel_theme_options[service_section_enable]', array(
	'label'             => esc_html__( 'Services Section Enable', 'ultravel' ),
	'section'           => 'ultravel_about_section',
	'on_off_label' 		=> ultravel_switch_options(),
	'active_callback'   => function( $control ) {
		return (
			ultravel_is_about_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[service_section_enable]', array(
		'selector'      => '#ultravel_about_section .tooltiptext',
		'settings'      => 'ultravel_theme_options[service_section_enable]',
    ) );
}

// Services Excerpt length setting and control.
$wp_customize->add_setting( 'ultravel_theme_options[service_excerpt_length]',
	array(
		'sanitize_callback' => 'ultravel_sanitize_number_range',
		'default'			=> $options['service_excerpt_length'],
	)
);

$wp_customize->add_control( 'ultravel_theme_options[service_excerpt_length]',
	array(
		'label'       		=> esc_html__( 'Excerpt Length', 'ultravel' ),
		'description' 		=> esc_html__( 'Total words to be displayed in Services section', 'ultravel' ),
		'section'     		=> 'ultravel_about_section',
		'type'        		=> 'number',
		'active_callback'   => function( $control ) {
			return (
				ultravel_is_service_section_enable( $control ) && ultravel_is_about_section_enable( $control )
			);
		},
	)
);


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

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

	$wp_customize->add_control( new Ultravel_Dropdown_Chooser( $wp_customize, 'ultravel_theme_options[service_content_page_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Page %d', 'ultravel' ), $i ),
		'section'           => 'ultravel_about_section',
		'choices'			=> ultravel_page_choices(),
		'active_callback'   => function( $control ) {
			return (
				ultravel_is_service_section_enable( $control ) && ultravel_is_about_section_enable( $control )
			);
		},
	) ) );

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

	$wp_customize->add_control( new Ultravel_Icon_Picker( $wp_customize, 'ultravel_theme_options[service_content_icon_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Icon %d', 'ultravel' ), $i ),
		'section'           => 'ultravel_about_section',
		'active_callback'   => function( $control ) {
			return (
				ultravel_is_service_section_enable( $control ) && ultravel_is_about_section_enable( $control )
			);
		},
	) ) );

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

	$wp_customize->add_control( new Ultravel_Customize_Horizontal_Line( $wp_customize, 'ultravel_theme_options[service_hr_'. $i .']',
		array(
			'section'         => 'ultravel_about_section',
			'active_callback' => 'ultravel_is_service_section_enable',
			'type'			  => 'hr'
	) ) );

endfor;