<?php

/**
 * Service Section
 *
 * @package doctor_physician
 */

$wp_customize->add_section(
	'doctor_physician_service_section',
	array(
		'panel'    => 'doctor_physician_front_page_options',
		'title'    => esc_html__( 'Service Section', 'doctor-physician' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Doctor_Physician_Toggle_Switch_Custom_Control(
		$wp_customize,
		'doctor_physician_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Service Section', 'doctor-physician' ),
			'section'  => 'doctor_physician_service_section',
			'settings' => 'doctor_physician_enable_service_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'doctor_physician_about_heading',
	array(
		'label'           => esc_html__( 'Service Heading', 'doctor-physician' ),
		'section'         => 'doctor_physician_service_section',
		'settings'        => 'doctor_physician_about_heading',
		'type'            => 'text',
		'active_callback' => 'doctor_physician_is_service_section_enabled',
	)
);

// Service Section - Content Type.
$wp_customize->add_setting(
	'doctor_physician_service_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'doctor_physician_sanitize_select',
	)
);

$wp_customize->add_control(
	'doctor_physician_service_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'doctor-physician' ),
		'section'         => 'doctor_physician_service_section',
		'settings'        => 'doctor_physician_service_content_type',
		'type'            => 'select',
		'active_callback' => 'doctor_physician_is_service_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'doctor-physician' ),
			'post' => esc_html__( 'Post', 'doctor-physician' ),
		),
	)
);

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

// Add custom control for Services Category with conditional visibility.
$wp_customize->add_control(new Doctor_Physician_Customize_Category_Dropdown_Control($wp_customize, 'doctor_physician_services_category', array(
	'label'    => __('Select Services Category', 'doctor-physician'),
	'section'  => 'doctor_physician_service_section',
	'settings' => 'doctor_physician_services_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('doctor_physician_service_content_type')->value() === 'post';
	},
)));


for ( $doctor_physician_i = 1; $doctor_physician_i <= 4; $doctor_physician_i++ ) {

	// icon // 
	$wp_customize->add_setting(
		'doctor_physician_service_icon' . $doctor_physician_i,
		array(
	        'default' => '',
			'sanitize_callback' => 'sanitize_text_field',
			'capability' => 'edit_theme_options',
			
		)
	);	

	$wp_customize->add_control(new Doctor_Physician_Change_Icon_Control($wp_customize, 
		'doctor_physician_service_icon' . $doctor_physician_i,
		array(
		    'label'   		=> __('Service  Icon','doctor-physician'),
		    'section' 		=> 'doctor_physician_service_section',
			'iconset' => 'fa',
			'active_callback' => 'doctor_physician_is_service_section_enabled',
		))  
	);

	// Service Section - Select Post.
	$wp_customize->add_setting(
		'doctor_physician_service_content_post_' . $doctor_physician_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'doctor_physician_service_content_post_' . $doctor_physician_i,
		array(
			'label'           => esc_html__( 'Select Post ', 'doctor-physician' ) . $doctor_physician_i,
			'description'     => sprintf( esc_html__( 'Kindly :- Select a Post based on the category selected in the upper settings', 'doctor-physician' ), $doctor_physician_i ),
			'section'         => 'doctor_physician_service_section',
			'settings'        => 'doctor_physician_service_content_post_' . $doctor_physician_i,
			'active_callback' => 'doctor_physician_is_service_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => doctor_physician_get_post_choices(),
		)
	);

	// Service Section - Select Page.
	$wp_customize->add_setting(
		'doctor_physician_service_content_page_' . $doctor_physician_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'doctor_physician_service_content_page_' . $doctor_physician_i,
		array(
			'label'           => esc_html__( 'Select Page ', 'doctor-physician' ) . $doctor_physician_i,
			'section'         => 'doctor_physician_service_section',
			'settings'        => 'doctor_physician_service_content_page_' . $doctor_physician_i,
			'active_callback' => 'doctor_physician_is_service_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => doctor_physician_get_page_choices(),
		)
	);
}

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

$wp_customize->add_control(
	'doctor_physician_service_main_button_label',
	array(
		'label'           => esc_html__( 'Section Button Label', 'doctor-physician' ),
		'section'         => 'doctor_physician_service_section',
		'settings'        => 'doctor_physician_service_main_button_label',
		'type'            => 'text',
		'active_callback' => 'doctor_physician_is_service_section_enabled',
	)
);

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

$wp_customize->add_control(
	'doctor_physician_service_main_button_url',
	array(
		'label'           => esc_html__( 'Section Button Url', 'doctor-physician' ),
		'section'         => 'doctor_physician_service_section',
		'settings'        => 'doctor_physician_service_main_button_url',
		'type'            => 'url',
		'active_callback' => 'doctor_physician_is_service_section_enabled',
	)
);

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

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