<?php

function the_tour_operator_remove_customize_register() {
    global $wp_customize;

    $wp_customize->remove_setting( 'adventure_travelling_mail_text' );
    $wp_customize->remove_control( 'adventure_travelling_mail_text' );

    $wp_customize->remove_setting( 'adventure_travelling_call_text' );
    $wp_customize->remove_control( 'adventure_travelling_call_text' );

    $wp_customize->remove_setting( 'adventure_travelling_call' );
    $wp_customize->remove_control( 'adventure_travelling_call' );

    $wp_customize->remove_setting( 'adventure_travelling_call_icon' );
    $wp_customize->remove_control( 'adventure_travelling_call_icon' );

    $wp_customize->remove_setting( 'adventure_travelling_slider_content_layout' );
    $wp_customize->remove_control( 'adventure_travelling_slider_content_layout' );
   
}
add_action( 'customize_register', 'the_tour_operator_remove_customize_register', 11 );

if ( ! defined( 'THE_TOUR_OPERATOR_TEXT' ) ) {
    define( 'THE_TOUR_OPERATOR_TEXT', __( 'The Tour Operator Pro','the-tour-operator' ));
}
if ( ! defined( 'THE_TOUR_OPERATOR_BUY_TEXT' ) ) {
    define( 'THE_TOUR_OPERATOR_BUY_TEXT', __( 'Upgrade Pro','the-tour-operator' ));
}


add_action( 'customize_register', function( $manager ) {

// Load custom sections.
load_template( trailingslashit( get_template_directory() ) . '/inc/section-pro.php' );

    $manager->register_section_type( Adventure_Travelling_Button::class );

    $manager->add_section(
        new Adventure_Travelling_Button( $manager, 'adventure_travelling_pro', [
            'title'       => esc_html( THE_TOUR_OPERATOR_TEXT,'the-tour-operator' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'the-tour-operator' ),
            'button_url'  => esc_url( ADVENTURE_TRAVELLING_PRO_THEME_URL )
        ] )
    );

} );

function the_tour_operator_customize_register( $wp_customize ) {

	// Pro Version
    class the_tour_operator_Customize_Pro_Version extends WP_Customize_Control {
        public $type = 'pro_options';

        public function render_content() {
            echo '<span>Unlock Premium <strong>'. esc_html( $this->label ) .'</strong>? </span>';
            echo '<a href="'. esc_url($this->description) .'" target="_blank">';
                echo '<span class="dashicons dashicons-info"></span>';
                echo '<strong> '. esc_html( THE_TOUR_OPERATOR_BUY_TEXT,'the-tour-operator' ) .'<strong></a>';
            echo '</a>';
        }
    }

    // Custom Controls
    function the_tour_operator_sanitize_custom_control( $input ) {
        return $input;
    }
	
	// Register the custom control type.
	$wp_customize->register_control_type( 'The_Tour_Operator_Toggle_Control' );

  	$wp_customize->add_setting('the_tour_operator_slider_content_layout',array(
        'default' => 'LEFT-ALIGN',
        'priority'=> 2,
        'sanitize_callback' => 'adventure_travelling_sanitize_choices'
	));
	$wp_customize->add_control('the_tour_operator_slider_content_layout',array(
        'type' => 'radio',
        'label'     => __('Slider Content Layout', 'the-tour-operator'),
        'section' => 'adventure_travelling_slider_section',
        'choices' => array(
        	'LEFT-ALIGN' => __('LEFT-ALIGN','the-tour-operator'),
            'CENTER-ALIGN' => __('CENTER-ALIGN','the-tour-operator'),
            'RIGHT-ALIGN' => __('RIGHT-ALIGN','the-tour-operator'),
        ),
	) );


	// Trip Offer Settings
	$wp_customize->add_section( 'the_tour_operator_trip_offer_section' , array(
    	'title'      => __( 'Trip Offers Settings', 'the-tour-operator' ),
		'panel' => 'adventure_travelling_panel_id',
		'priority' => 5,
	) );

    $wp_customize->add_setting( 'the_tour_operator_offer_show_hide', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'adventure_travelling_sanitize_checkbox',
	) );
	$wp_customize->add_control( new The_Tour_Operator_Toggle_Control( $wp_customize, 'the_tour_operator_offer_show_hide', array(
		'label'       => esc_html__( 'Show / Hide section', 'the-tour-operator' ),
		'section'     => 'the_tour_operator_trip_offer_section',
		'type'        => 'toggle',
		'settings'    => 'the_tour_operator_offer_show_hide',
	) ) );

	$wp_customize->add_setting( 'the_tour_operator_offer_animation', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'adventure_travelling_sanitize_checkbox',
	) );
	$wp_customize->add_control( new adventure_travelling_Toggle_Control( $wp_customize, 'the_tour_operator_offer_animation', array(
		'label'       => esc_html__( 'Show / Hide Animation', 'the-tour-operator' ),
		'section'     => 'the_tour_operator_trip_offer_section',
		'type'        => 'toggle',
		'settings'    => 'the_tour_operator_offer_animation',
	) ) );

	$wp_customize->add_setting('the_tour_operator_offer_section_short_title',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('the_tour_operator_offer_section_short_title',array(
		'label'	=> __('Short Title','the-tour-operator'),
		'section'	=> 'the_tour_operator_trip_offer_section',
		'type'		=> 'text'
	));
	$wp_customize->selective_refresh->add_partial( 'the_tour_operator_offer_section_short_title', array(
		'selector' => '#travel-offer h6',
		'render_callback' => 'the_tour_operator_customize_partial_the_tour_operator_offer_section_short_title',
	) );

	$wp_customize->add_setting('the_tour_operator_offer_section_tittle',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('the_tour_operator_offer_section_tittle',array(
		'label'	=> __('Section Title','the-tour-operator'),
		'section'	=> 'the_tour_operator_trip_offer_section',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('the_tour_operator_offer_section_text',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('the_tour_operator_offer_section_text',array(
		'label'	=> __('Section Description','the-tour-operator'),
		'section'	=> 'the_tour_operator_trip_offer_section',
		'type'		=> 'text'
	));

	$categories = get_categories();
	$cats = array();
	$i = 0;
	$offer_cat[]= 'select';
	foreach($categories as $category){
		if($i==0){
			$default = $category->slug;
			$i++;
		}
		$offer_cat[$category->slug] = $category->name;
	}

	$wp_customize->add_setting('the_tour_operator_offer_section_category',array(
		'default'	=> 'select',
		'sanitize_callback' => 'adventure_travelling_sanitize_choices',
	));
	$wp_customize->add_control('the_tour_operator_offer_section_category',array(
		'type'    => 'select',
		'choices' => $offer_cat,
		'label' => __('Select Category','the-tour-operator'),
		'section' => 'the_tour_operator_trip_offer_section',
	));

	// Pro Version
    $wp_customize->add_setting( 'the_tour_operator_services_pro_version_logo', array(
        'sanitize_callback' => 'the_tour_operator_sanitize_custom_control'
    ));
    $wp_customize->add_control( new the_tour_operator_Customize_Pro_Version ( $wp_customize,'the_tour_operator_services_pro_version_logo', array(
        'section'     => 'the_tour_operator_trip_offer_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'the-tour-operator' ),
        'description' => esc_url( ADVENTURE_TRAVELLING_PRO_THEME_URL ),
    )));

}
add_action( 'customize_register', 'the_tour_operator_customize_register' );
