<?php

/**
 * Bike Services Section
 *
 * @package bike_workshop
 */

$wp_customize->add_section(
	'bike_workshop_services_section',
	array(
		'panel'    => 'bike_workshop_front_page_options',
		'title'    => esc_html__( 'Bike Services Section', 'bike-workshop' ),
		'priority' => 10,
	)
);

// Services Section - Enable Section.
$wp_customize->add_setting(
	'bike_workshop_enable_services_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'bike_workshop_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Bike_Workshop_Toggle_Switch_Custom_Control(
		$wp_customize,
		'bike_workshop_enable_services_section',
		array(
			'label'    => esc_html__( 'Enable Services Section', 'bike-workshop' ),
			'section'  => 'bike_workshop_services_section',
			'settings' => 'bike_workshop_enable_services_section',
		)
	)
);

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

// Bike Services Section
$wp_customize->add_setting(
	'bike_workshop_heading_services_section',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'bike_workshop_heading_services_section',
	array(
		'label'           => esc_html__( 'Heading', 'bike-workshop' ),
		'section'         => 'bike_workshop_services_section',
		'settings'        => 'bike_workshop_heading_services_section',
		'type'            => 'text',
		'active_callback' => 'bike_workshop_is_services_section_enabled',
	)
);

$wp_customize->add_setting(
	'bike_workshop_services_number',
	array(
	    'default'=> '',
	    'sanitize_callback' => 'sanitize_text_field'
));
$wp_customize->add_control(
	'bike_workshop_services_number',
	array(
	    'label' => esc_html__('No of Tabs to show','bike-workshop'),
		'description' => esc_html__('Set the number of tabs, then click "Publish" and refresh the page to see changes.', 'bike-workshop'),
	    'section'=> 'bike_workshop_services_section',
	    'type' => 'number',
	    'input_attrs' => array(
	    'step'  => 1,
			'min'  => 0,
			'max'  => 4,
	    ),
	    'active_callback' => 'bike_workshop_is_services_section_enabled',
	)
);

$bike_workshop_featured_post = get_theme_mod('bike_workshop_services_number');
for ( $bike_workshop_j = 1; $bike_workshop_j <= $bike_workshop_featured_post; $bike_workshop_j++ ) {

	$wp_customize->add_setting(
        'bike_workshop_services_text' . $bike_workshop_j,
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'bike_workshop_services_text' . $bike_workshop_j,
        array(
            'label'           => esc_html__('Tab ', 'bike-workshop') . $bike_workshop_j,
            'section'         => 'bike_workshop_services_section',
            'type'            => 'text',
            'active_callback' => 'bike_workshop_is_services_section_enabled',
        )
    );

    $bike_workshop_categories = get_categories();
        $bike_workshop_cat_posts = array();
            $bike_workshop_i = 0;
            $bike_workshop_cat_posts[]='Select';
        foreach($bike_workshop_categories as $bike_workshop_category){
            if($bike_workshop_i==0){
            $bike_workshop_default = $bike_workshop_category->slug;
            $bike_workshop_i++;
        }
        $bike_workshop_cat_posts[$bike_workshop_category->slug] = $bike_workshop_category->name;
    }

    $wp_customize->add_setting(
    	'bike_workshop_services_category'.$bike_workshop_j,
    	array(
	        'default'   => 'services',
	        'sanitize_callback' => 'bike_workshop_sanitize_choices',
    	)
    );
    $wp_customize->add_control(
    	'bike_workshop_services_category'.$bike_workshop_j,
    	array(
	        'type'    => 'select',
	        'choices' => $bike_workshop_cat_posts,
	        'label' => __('Select Category to display Services','bike-workshop'),
	        'section' => 'bike_workshop_services_section',
	        'active_callback' => 'bike_workshop_is_services_section_enabled',
    	)
    );
}

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

$wp_customize->add_control(
	'bike_workshop_service_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(BIKE_WORKSHOP_PREMIUM_PAGE) ." '>Upgrade Pro</a>
				</div>
			</div>
		",
		'section' => 'bike_workshop_services_section'
	)
);