<?php
/**
 * Rearrange Sections
 *
 * @package Travel Tour
 */
add_action( 'customize_register', 'travel_tour_sort_homepage_sections' );

function travel_tour_sort_homepage_sections( $wp_customize ) {

	$wp_customize->add_section( 'travel_tour_sort_homepage_sections', array(
	    'title'          => esc_html__( 'Rearrange Home Sections', 'travel-tour' ),
	    'description'    => esc_html__( 'Rearrange Home Sections', 'travel-tour' ),
	    'panel'          => '',
	    'priority'       => 10,
	) );

	if( class_exists( 'Wp_Travel_Engine' ) ) {
		$default = array(
			'banner-section',
			'search-section',
			'info-section',
			'slider-section',
			'trips-section',
			'offer-section',
			'cta-section',
			'blog-section',
			'testimonial-section'
		);
		$choices = array(			
			'banner-section' => esc_html__( 'Banner Section', 'travel-tour' ),
			'search-section' => esc_html__( 'Search Section', 'travel-tour' ),
			'info-section' => esc_html__( 'Quick Info Section', 'travel-tour' ),
			'slider-section' => esc_html__( 'Slider Section', 'travel-tour' ),
			'trips-section' => esc_html__( 'Trips Section', 'travel-tour' ),
			'offer-section' => esc_html__( 'Offer Section', 'travel-tour' ),
			'cta-section' => esc_html__( 'CTA Section', 'travel-tour' ),
			'blog-section' => esc_html__( 'Blog Section', 'travel-tour' ),
			'testimonial-section' => esc_html__( 'Testimonial Section', 'travel-tour' ),
		);
	} else {
		$default = array(
			'banner-section',
			'info-section',
			'cta-section',
			'blog-section',
			'testimonial-section'
		);
		$choices = array(			
			'banner-section' => esc_html__( 'Banner Section', 'travel-tour' ),
			'info-section' => esc_html__( 'Quick Info Section', 'travel-tour' ),
			'cta-section' => esc_html__( 'CTA Section', 'travel-tour' ),
			'blog-section' => esc_html__( 'Blog Section', 'travel-tour' ),
			'testimonial-section' => esc_html__( 'Testimonial Section', 'travel-tour' ),
		);
	}

	$wp_customize->add_setting( 'travel_tour_sort_homepage', array(
        'capability'  => 'edit_theme_options',
        'sanitize_callback'	=> 'travel_tour_sanitize_array',
        'default'     => $default
    ) );

    $wp_customize->add_control( new Travel_Tour_Control_Sortable(
    	$wp_customize, 'travel_tour_sort_homepage', array(
        'label' => esc_html__( 'Drag and Drop Sections to rearrange.', 'travel-tour' ),
        'section' => 'travel_tour_sort_homepage_sections',
        'settings' => 'travel_tour_sort_homepage',
        'type'=> 'sortable',
        'disabled'     => fs_travel_tour()->is_free_plan(),
        'choices'     => $choices
    	)
    ) );

    if ( fs_travel_tour()->is_free_plan() ) {
        $wp_customize->add_setting( 'travel_tour_sort_homepage_upgrade_to_pro', array(
            'sanitize_callback' => null,
        ) );
        $wp_customize->add_control( new Travel_Tour_Control_Upgrade_To_Pro(
            $wp_customize, 'travel_tour_sort_homepage_upgrade_to_pro', array(
                'section' => 'travel_tour_sort_homepage_sections',
                'settings'    => 'travel_tour_sort_homepage_upgrade_to_pro',
                'title'   => __( 'Rearrange homepage sections and prioritize what your visitors should see first.', 'travel-tour' ),
                'items' => array(
                    'one'   => array(
                        'title' => __( 'Rearrange sections on the Homepage', 'travel-tour' ),
                    ),
                ),
                'button_url'   => esc_url( 'https://thebootstrapthemes.com/travel-tour/#free-vs-pro' ),
                'button_text'   => __( 'Upgrade Now', 'travel-tour' ),
            )
        ) );
    }

}