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

$wp_customize->add_section(
	'appointment_management_services_section',
	array(
		'panel'    => 'appointment_management_front_page_options',
		'title'    => esc_html__( 'Services Section', 'appointment-management' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Appointment_Management_Toggle_Switch_Custom_Control(
		$wp_customize,
		'appointment_management_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Services Section', 'appointment-management' ),
			'section'  => 'appointment_management_services_section',
			'settings' => 'appointment_management_enable_service_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'appointment_management_trending_product_heading',
	array(
		'label'           => esc_html__( 'Heading', 'appointment-management' ),
		'section'         => 'appointment_management_services_section',
		'settings'        => 'appointment_management_trending_product_heading',
		'type'            => 'text',
		'active_callback' => 'appointment_management_is_service_section_enabled',
	)
);

// Services Section - Content Type.
$wp_customize->add_setting(
	'appointment_management_service_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'appointment_management_sanitize_select',
	)
);

$wp_customize->add_control(
	'appointment_management_service_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'appointment-management' ),
		'section'         => 'appointment_management_services_section',
		'settings'        => 'appointment_management_service_content_type',
		'type'            => 'select',
		'active_callback' => 'appointment_management_is_service_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'appointment-management' ),
			'post' => esc_html__( 'Post', 'appointment-management' ),
		),
	)
);

// Services Category Setting.
$wp_customize->add_setting('appointment_management_services_category', array(
	'default'           => 'services',
	'sanitize_callback' => 'sanitize_text_field',
));

// Add custom control for Services Category with conditional visibility.
$wp_customize->add_control(new Appointment_Management_Customize_Category_Dropdown_Control($wp_customize, 'appointment_management_services_category', array(
	'label'    => __('Select Services Category', 'appointment-management'),
	'section'  => 'appointment_management_services_section',
	'settings' => 'appointment_management_services_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('appointment_management_service_content_type')->value() === 'post';
	},
)));


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

	$wp_customize->add_control(
		'appointment_management_service_content_post_' . $appointment_management_i,
		array(
			'label'           => esc_html__( 'Select Post ', 'appointment-management' ) . $appointment_management_i,
			'description'     => sprintf( esc_html__( 'Kindly :- Select a Post based on the category selected in the upper settings', 'appointment-management' ), $appointment_management_i ),
			'section'         => 'appointment_management_services_section',
			'settings'        => 'appointment_management_service_content_post_' . $appointment_management_i,
			'active_callback' => 'appointment_management_is_service_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => appointment_management_get_post_choices(),
		)
	);

}

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

$wp_customize->add_control(
	'appointment_management_service_button_label_',
	array(
		'label'           => esc_html__( 'Button Label', 'appointment-management'  ),
		'section'         => 'appointment_management_services_section',
		'settings'        => 'appointment_management_service_button_label_',
		'type'            => 'text',
		'active_callback' => 'appointment_management_is_service_section_enabled',
	)
);

// Service Section - Button Link.
$wp_customize->add_setting(
	'appointment_management_service_button_link_',
	array(
		'default'           => '',
		'sanitize_callback' => 'esc_url_raw',
	)
);

$wp_customize->add_control(
	'appointment_management_service_button_link_',
	array(
		'label'           => esc_html__( 'Button Link', 'appointment-management' ),
		'section'         => 'appointment_management_services_section',
		'settings'        => 'appointment_management_service_button_link_',
		'type'            => 'url',
		'active_callback' => 'appointment_management_is_service_section_enabled',
	)
);

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

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