<?php

function travel_hub_remove_customize_register() {
    global $wp_customize;

    $wp_customize->remove_setting( 'adventure_travelling_tp_color_option_link' );
    $wp_customize->remove_control( 'adventure_travelling_tp_color_option_link' );
    
    $wp_customize->remove_setting( 'adventure_travelling_slider_content_layout' );
    $wp_customize->remove_control( 'adventure_travelling_slider_content_layout' );

}

add_action( 'customize_register', 'travel_hub_remove_customize_register', 11 );

if ( ! defined( 'TRAVEL_HUB_TEXT' ) ) {
    define( 'TRAVEL_HUB_TEXT', __( 'Travel Hub Pro','travel-hub' ));
}
if ( ! defined( 'TRAVEL_HUB_BUY_TEXT' ) ) {
    define( 'TRAVEL_HUB_BUY_TEXT', __( 'Upgrade Pro','travel-hub' ));
}

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( TRAVEL_HUB_TEXT,'travel-hub' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'travel-hub' ),
            'button_url'  => esc_url( ADVENTURE_TRAVELLING_PRO_THEME_URL )
        ] )
    );

} );

function travel_hub_customize_register( $wp_customize ) {

	// Pro Version
    class Travel_Hub_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( TRAVEL_HUB_BUY_TEXT,'travel-hub' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

	$wp_customize->add_setting( 'travel_hub_tp_secondary_color_option', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'travel_hub_tp_secondary_color_option', array(
	    'description' => __('It will change the complete theme secondary color in one click.', 'travel-hub'),
	    'section' => 'adventure_travelling_color_option',
	    'settings' => 'travel_hub_tp_secondary_color_option',
  	)));

  	$wp_customize->add_setting('travel_hub_slider_content_layout',array(
        'default' => 'LEFT-ALIGN',
        'sanitize_callback' => 'adventure_travelling_sanitize_choices'
	));
	$wp_customize->add_control('travel_hub_slider_content_layout',array(
        'type' => 'radio',
        'label'     => __('Slider Content Layout', 'travel-hub'),
        'section' => 'adventure_travelling_slider_section',
        'choices' => array(
        	'LEFT-ALIGN' => __('LEFT-ALIGN','travel-hub'),
            'CENTER-ALIGN' => __('CENTER-ALIGN','travel-hub'),
            'RIGHT-ALIGN' => __('RIGHT-ALIGN','travel-hub'),
        ),
	) );

    //trip offer setting
	$wp_customize->add_section( 'travel_hub_trip_offer_section' , array(
    	'title'      => __( 'Trip Offers Settings', 'travel-hub' ),
		'panel' => 'adventure_travelling_panel_id',
		'priority' => 6,
	) );

    $wp_customize->add_setting( 'travel_hub_offer_show_hide', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'adventure_travelling_sanitize_checkbox',
	) );
	$wp_customize->add_control( new Travel_Hub_Toggle_Control( $wp_customize, 'travel_hub_offer_show_hide', array(
		'label'       => esc_html__( 'Show / Hide section', 'travel-hub' ),
		'section'     => 'travel_hub_trip_offer_section',
		'type'        => 'toggle',
		'settings'    => 'travel_hub_offer_show_hide',
	) ) );

	$wp_customize->add_setting('travel_hub_offer_section_short_title',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('travel_hub_offer_section_short_title',array(
		'label'	=> __('Short Title','travel-hub'),
		'section'	=> 'travel_hub_trip_offer_section',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('travel_hub_offer_section_tittle',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('travel_hub_offer_section_tittle',array(
		'label'	=> __('Section Title','travel-hub'),
		'section'	=> 'travel_hub_trip_offer_section',
		'type'		=> 'text'
	));
	
	$wp_customize->add_setting('travel_hub_offer_section_text',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('travel_hub_offer_section_text',array(
		'label'	=> __('Section Description','travel-hub'),
		'section'	=> 'travel_hub_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('travel_hub_offer_section_category',array(
		'default'	=> 'select',
		'sanitize_callback' => 'adventure_travelling_sanitize_choices',
	));
	$wp_customize->add_control('travel_hub_offer_section_category',array(
		'type'    => 'select',
		'choices' => $offer_cat,
		'label' => __('Select Category','travel-hub'),
		'section' => 'travel_hub_trip_offer_section',
	));

	$wp_customize->add_setting('travel_hub_slider_top',array(
	    'default'=> '',
	    'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('travel_hub_slider_top',array(
	    'label' => __('Add Slider Top Text','travel-hub'),
	    'section'=> 'adventure_travelling_slider_section',
	    'type'=> 'text'
	));

	// Pro Version
    $wp_customize->add_setting( 'travel_hub_services_pro_version_logo', array(
        'sanitize_callback' => 'travel_hub_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Travel_Hub_Customize_Pro_Version ( $wp_customize,'travel_hub_services_pro_version_logo', array(
        'section'     => 'travel_hub_trip_offer_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'travel-hub' ),
        'description' => esc_url( ADVENTURE_TRAVELLING_PRO_THEME_URL ),
    )));

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