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

 $wp_customize->add_section(
	'online_school_courses_service_section',
	array(
		'panel'    => 'online_school_courses_front_page_options',
		'title'    => esc_html__( 'Program Section', 'online-school-courses' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Online_School_Courses_Toggle_Switch_Custom_Control(
		$wp_customize,
		'online_school_courses_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Service Section', 'online-school-courses' ),
			'section'  => 'online_school_courses_service_section',
			'settings' => 'online_school_courses_enable_service_section'
		)
	)
);

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

$wp_customize->add_control(
	'online_school_courses_trending_post_heading',
	array(
		'label'           => esc_html__( 'Heading', 'online-school-courses' ),
		'section'         => 'online_school_courses_service_section',
		'settings'        => 'online_school_courses_trending_post_heading',
		'type'            => 'text',
		'active_callback' => 'online_school_courses_is_service_section_enabled',
	)
);

// Add Separator Custom Control
$wp_customize->add_setting( 'online_school_courses_services_separators', array(
	'sanitize_callback' => 'sanitize_text_field',
) );

$wp_customize->add_control( new Online_School_Courses_Separator_Custom_Control( $wp_customize, 'online_school_courses_services_separators', array(
	'label' => __( 'Select Courses Category', 'online-school-courses' ),
	'section' => 'online_school_courses_service_section',
	'settings' => 'online_school_courses_services_separators',
	'active_callback' => 'online_school_courses_is_service_section_enabled',
)));

// Add setting for Tutor LMS Course Category
$wp_customize->add_setting(
    'online_school_courses_services_category',
    array(
        'default'           => '',
        'sanitize_callback' => 'absint', // store term ID safely
    )
);

$wp_customize->add_control(
    'online_school_courses_services_category',
    array(
        'label'           => __( 'Select Courses Category', 'online-school-courses' ),
        'section'         => 'online_school_courses_service_section',
        'settings'        => 'online_school_courses_services_category',
        'type'            => 'select',
        'choices'         => wp_list_pluck( get_terms( array(
            'taxonomy'   => 'course-category',
            'hide_empty' => false,
        ) ), 'name', 'term_id' ),
        'active_callback' => 'online_school_courses_is_service_section_enabled',
    )
);

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

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

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