<?php
/**
 * Travel Section
 *
 * @package aster_travel_blog
 */

$wp_customize->add_section(
	'aster_travel_blog_menu_section',
	array(
		'panel'    => 'aster_travel_blog_front_page_options',
		'title'    => esc_html__( 'Travel Section', 'aster-travel-blog' ),
		'priority' => 10,
	)
);

// Travel Section - Enable Section.
$wp_customize->add_setting(
	'aster_travel_blog_enable_travel_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'aster_travel_blog_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Aster_Travel_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'aster_travel_blog_enable_travel_section',
		array(
			'label'    => esc_html__( 'Enable Travel Section', 'aster-travel-blog' ),
			'section'  => 'aster_travel_blog_menu_section',
			'settings' => 'aster_travel_blog_enable_travel_section',
		)
	)
);

if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'aster_travel_blog_enable_travel_section',
		array(
			'selector' => '#aster_travel_blog_travel_section .section-link',
			'settings' => 'aster_travel_blog_enable_travel_section',
		)
	);
}

// Trending Products Section
$wp_customize->add_setting(
	'aster_travel_blog_heading_travel_section',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'aster_travel_blog_heading_travel_section',
	array(
		'label'           => esc_html__( 'Heading', 'aster-travel-blog' ),
		'section'         => 'aster_travel_blog_menu_section',
		'settings'        => 'aster_travel_blog_heading_travel_section',
		'type'            => 'text',
		'active_callback' => 'aster_travel_blog_is_travel_section_enabled',
	)
);

$wp_customize->add_setting(
	'aster_travel_blog_travel_number',
	array(
	    'default'=> '',
	    'sanitize_callback' => 'sanitize_text_field'
));
$wp_customize->add_control(
	'aster_travel_blog_travel_number',
	array(
	    'label' => esc_html__('No of Tabs to show','aster-travel-blog'),
	    'section'=> 'aster_travel_blog_menu_section',
	    'type' => 'number',
	    'input_attrs' => array(
	    'step'  => 1,
			'min'  => 0,
			'max'  => 5,
	    ),
	    'active_callback' => 'aster_travel_blog_is_travel_section_enabled',
	)
);

$aster_travel_blog_featured_post = get_theme_mod('aster_travel_blog_travel_number');
for ( $aster_travel_blog_j = 1; $aster_travel_blog_j <= $aster_travel_blog_featured_post; $aster_travel_blog_j++ ) {

    $wp_customize->add_setting(
    	'aster_travel_blog_travel_text'.$aster_travel_blog_j,
    	array(
	        'default'=> '',
	        'sanitize_callback' => 'sanitize_text_field'
    	)
    );
    $wp_customize->add_control(
    	'aster_travel_blog_travel_text'.$aster_travel_blog_j,
    	array(
	        'label' => esc_html__('Tab ','aster-travel-blog').$aster_travel_blog_j,
	        'section'=> 'aster_travel_blog_menu_section',
	        'type'=> 'text',
	        'active_callback' => 'aster_travel_blog_is_travel_section_enabled',
    	)
    );

    $aster_travel_blog_categories = get_categories();
        $aster_travel_blog_cat_posts = array();
            $aster_travel_blog_i = 0;
            $aster_travel_blog_cat_posts[]='Travel';
        foreach($aster_travel_blog_categories as $aster_travel_blog_category){
            if($aster_travel_blog_i==0){
            $aster_travel_blog_default = $aster_travel_blog_category->slug;
            $aster_travel_blog_i++;
        }
        $aster_travel_blog_cat_posts[$aster_travel_blog_category->slug] = $aster_travel_blog_category->name;
    }

    $wp_customize->add_setting(
    	'aster_travel_blog_travel_category'.$aster_travel_blog_j,
    	array(
	        'default'   => 'Travel',
	        'sanitize_callback' => 'aster_travel_blog_sanitize_choices',
    	)
    );
    $wp_customize->add_control(
    	'aster_travel_blog_travel_category'.$aster_travel_blog_j,
    	array(
	        'type'    => 'select',
	        'choices' => $aster_travel_blog_cat_posts,
	        'label' => __('Select Category to display projects','aster-travel-blog'),
	        'section' => 'aster_travel_blog_menu_section',
	        'active_callback' => 'aster_travel_blog_is_travel_section_enabled',
    	)
    );
}

$wp_customize->add_setting( 
	'aster_travel_blog_menu_settings_upgraded_features',
	array(
		'sanitize_callback' => 'sanitize_text_field'
	)
);

$wp_customize->add_control(
	'aster_travel_blog_menu_settings_upgraded_features', 
	array(
		'type'=> 'hidden',
		'description' => "
			<div class='customizer-upgraded-features'>
				<i class='fas fa-info-circle'></i>
				<span class='pro-text'>
					Unlock Premium <strong>Features</strong> ?<br>
					<a target='_blank' href='". esc_url(ASTER_TRAVEL_BLOG_PREMIUM_PAGE) ." '>Upgrade Pro</a>
				</div>
			</div>
		",
		'section' => 'aster_travel_blog_menu_section'
	)
);