<?php
/**
 * Service Section
 *
 * @package aster_it_courses
 */

 $wp_customize->add_section(
	'aster_it_courses_service_section',
	array(
		'panel'    => 'aster_it_courses_front_page_options',
		'title'    => esc_html__( 'Courses Section', 'aster-it-courses' ),
		'priority' => 10,
	)
);

//Service Section - Enable Section.
$wp_customize->add_setting(
	'aster_it_courses_enable_service_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'aster_it_courses_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Aster_IT_Courses_Toggle_Switch_Custom_Control(
		$wp_customize,
		'aster_it_courses_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Courses Section', 'aster-it-courses' ),
			'section'  => 'aster_it_courses_service_section',
			'settings' => 'aster_it_courses_enable_service_section'
		)
	)
);

// Service Section - Content Label.
$wp_customize->add_setting(
	'aster_it_courses_trending_post_content',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'aster_it_courses_trending_post_content',
	array(
		'label'           => esc_html__( 'Sub Heading', 'aster-it-courses' ),
		'section'         => 'aster_it_courses_service_section',
		'settings'        => 'aster_it_courses_trending_post_content',
		'type'            => 'text',
		'active_callback' => 'aster_it_courses_is_service_section_enabled',
	)
);

// Service Section - Heading Label.
$wp_customize->add_setting(
	'aster_it_courses_trending_post_heading',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'aster_it_courses_trending_post_heading',
	array(
		'label'           => esc_html__( 'Heading', 'aster-it-courses' ),
		'section'         => 'aster_it_courses_service_section',
		'settings'        => 'aster_it_courses_trending_post_heading',
		'type'            => 'text',
		'active_callback' => 'aster_it_courses_is_service_section_enabled',
	)
);

// Number of Service Posts to Show
$wp_customize->add_setting('aster_it_courses_service_post_count',array(
	'default'	=> '',
	'sanitize_callback'	=> 'sanitize_text_field',
));
$wp_customize->add_control('aster_it_courses_service_post_count',array(
	'label'	=> __('Number of courses to show','aster-it-courses'),
	'description' => __('Add number and refresh tab','aster-it-courses'),
	'section'	=> 'aster_it_courses_service_section',
	'type'		=> 'number',
	'active_callback' => 'aster_it_courses_is_service_section_enabled',
	'input_attrs' => array(
		'step'             => 1,
		'min'              => 0,
		'max'              => 12,
	)
));
$aster_it_courses_featured_post = get_theme_mod('aster_it_courses_service_post_count');

for ( $aster_it_courses_i = 1; $aster_it_courses_i <= $aster_it_courses_featured_post; $aster_it_courses_i++ ) {
	
	// Service Section - Select Post.
	$wp_customize->add_setting(
		'aster_it_courses_service_content_post_' . $aster_it_courses_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'aster_it_courses_service_content_post_' . $aster_it_courses_i,
		array(
			'label'           => esc_html__( 'Select Post ', 'aster-it-courses' ) . $aster_it_courses_i,
			'section'         => 'aster_it_courses_service_section',
			'settings'        => 'aster_it_courses_service_content_post_' . $aster_it_courses_i,
			'type'            => 'select',
			'choices'         => aster_it_courses_get_post_choices(),
		)
	);
	
	$wp_customize->add_setting('aster_it_courses_author_image' . $aster_it_courses_i,
		array(
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control(
		new WP_Customize_Image_Control( $wp_customize,'aster_it_courses_author_image' . $aster_it_courses_i,
			array(
				'label' => __('Author Image ','aster-it-courses') . $aster_it_courses_i,
				'section' => 'aster_it_courses_service_section',
				'settings' => 'aster_it_courses_author_image' . $aster_it_courses_i,
			)
		)
	);

	$wp_customize->add_setting('aster_it_courses_author_name' . $aster_it_courses_i, array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('aster_it_courses_author_name' . $aster_it_courses_i, array(
		'label'    => __('Author Name ', 'aster-it-courses') . $aster_it_courses_i,
		'section'  => 'aster_it_courses_service_section',
		'type'     => 'text',
	));

	$wp_customize->add_setting('aster_it_courses_paper_count'.$aster_it_courses_i,array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('aster_it_courses_paper_count'.$aster_it_courses_i,array(
		'label'	=> esc_html__( 'Test Count', 'aster-it-courses' ),
		'section'	=> 'aster_it_courses_service_section',
		'type'		=> 'text',
		'input_attrs' => array(
		  'placeholder' => __( '50', 'aster-it-courses' ),
		),
	));

	$wp_customize->add_setting('aster_it_courses_degree_count'.$aster_it_courses_i,array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('aster_it_courses_degree_count'.$aster_it_courses_i,array(
		'label'	=> esc_html__( 'Students Count', 'aster-it-courses' ),
		'section'	=> 'aster_it_courses_service_section',
		'type'		=> 'text',
		'input_attrs' => array(
		  'placeholder' => __( '450', 'aster-it-courses' ),
		),
	));

	$wp_customize->add_setting('aster_it_courses_regular_price'.$aster_it_courses_i,array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('aster_it_courses_regular_price'.$aster_it_courses_i,array(
		'label'	=> esc_html__( 'Add Price', 'aster-it-courses' ),
		'section'	=> 'aster_it_courses_service_section',
		'type'		=> 'text',
		'input_attrs' => array(
		  'placeholder' => __( '$50.00', 'aster-it-courses' ),
		),
	));

}

// Partial Refresh
if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'aster_it_courses_enable_service_section',
		array(
			'selector' => '#aster_it_courses_service_section .section-link',
			'settings' => 'aster_it_courses_enable_service_section',
		)
	);
}

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

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