<?php
/**
 * Vehicle Services Section
 *
 * @package wheel_alignment_service
 */

$wp_customize->add_section(
	'wheel_alignment_service_services_section',
	array(
		'panel'    => 'wheel_alignment_service_front_page_options',
		'title'    => esc_html__( 'Vehicle Services Section', 'wheel-alignment-service' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Wheel_Alignment_Service_Toggle_Switch_Custom_Control(
		$wp_customize,
		'wheel_alignment_service_enable_services_section',
		array(
			'label'    => esc_html__( 'Enable Services Section', 'wheel-alignment-service' ),
			'section'  => 'wheel_alignment_service_services_section',
			'settings' => 'wheel_alignment_service_enable_services_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'wheel_alignment_service_heading_services_section',
	array(
		'label'           => esc_html__( 'Heading', 'wheel-alignment-service' ),
		'section'         => 'wheel_alignment_service_services_section',
		'settings'        => 'wheel_alignment_service_heading_services_section',
		'type'            => 'text',
		'active_callback' => 'wheel_alignment_service_is_services_section_enabled',
	)
);

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

$wheel_alignment_service_featured_post = get_theme_mod('wheel_alignment_service_services_number');
for ( $wheel_alignment_service_j = 1; $wheel_alignment_service_j <= $wheel_alignment_service_featured_post; $wheel_alignment_service_j++ ) {

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

    $wp_customize->add_control(
        'wheel_alignment_service_services_text' . $wheel_alignment_service_j,
        array(
            'label'           => esc_html__('Tab ', 'wheel-alignment-service') . $wheel_alignment_service_j,
            'section'         => 'wheel_alignment_service_services_section',
            'type'            => 'text',
            'active_callback' => 'wheel_alignment_service_is_services_section_enabled',
        )
    );

    $wheel_alignment_service_categories = get_categories();
        $wheel_alignment_service_cat_posts = array();
            $wheel_alignment_service_i = 0;
            $wheel_alignment_service_cat_posts[]='Select';
        foreach($wheel_alignment_service_categories as $wheel_alignment_service_category){
            if($wheel_alignment_service_i==0){
            $wheel_alignment_service_default = $wheel_alignment_service_category->slug;
            $wheel_alignment_service_i++;
        }
        $wheel_alignment_service_cat_posts[$wheel_alignment_service_category->slug] = $wheel_alignment_service_category->name;
    }

    $wp_customize->add_setting(
    	'wheel_alignment_service_services_category'.$wheel_alignment_service_j,
    	array(
	        'default'   => 'services',
	        'sanitize_callback' => 'wheel_alignment_service_sanitize_choices',
    	)
    );
    $wp_customize->add_control(
    	'wheel_alignment_service_services_category'.$wheel_alignment_service_j,
    	array(
	        'type'    => 'select',
	        'choices' => $wheel_alignment_service_cat_posts,
	        'label' => __('Select Category to display Services','wheel-alignment-service'),
	        'section' => 'wheel_alignment_service_services_section',
	        'active_callback' => 'wheel_alignment_service_is_services_section_enabled',
    	)
    );
}

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

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