<?php

/**
 * Services Section
 *
 * @package resort_motel
 */

$wp_customize->add_section(
	'resort_motel_service_section',
	array(
		'panel'    => 'resort_motel_front_page_options',
		'title'    => esc_html__( 'Hotel Rooms Section', 'resort-motel' ),
		'priority' => 10,
	)
);

//Hotel Room Section - Enable Section.
$wp_customize->add_setting(
	'resort_motel_enable_service_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'resort_motel_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Resort_Motel_Toggle_Switch_Custom_Control(
		$wp_customize,
		'resort_motel_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Hotel Rooms Section', 'resort-motel' ),
			'section'  => 'resort_motel_service_section',
			'settings' => 'resort_motel_enable_service_section'
		)
	)
);

// Hotel Room Options - Main Heading Text
$wp_customize->add_setting(
	'resort_motel_main_services_text',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'resort_motel_main_services_text',
	array(
		'label'           => esc_html__( 'Heading Text', 'resort-motel' ),
		'section'         => 'resort_motel_service_section',
		'type'            => 'text',
		'active_callback' => 'resort_motel_is_service_section_enabled',
	)
);

// Hotel Room Options - Main Heading
$wp_customize->add_setting(
	'resort_motel_main_services_heading',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'resort_motel_main_services_heading',
	array(
		'label'           => esc_html__( 'Main Heading', 'resort-motel' ),
		'section'         => 'resort_motel_service_section',
		'type'            => 'text',
		'active_callback' => 'resort_motel_is_service_section_enabled',
	)
);

// Hotel Room Section - Left Content Type.
$wp_customize->add_setting(
	'resort_motel_service_left_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'resort_motel_sanitize_select',
	)
);

$wp_customize->add_control(
	'resort_motel_service_left_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'resort-motel' ),
		'section'         => 'resort_motel_service_section',
		'settings'        => 'resort_motel_service_left_content_type',
		'type'            => 'select',
		'active_callback' => 'resort_motel_is_service_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'resort-motel' ),
			'post' => esc_html__( 'Post', 'resort-motel' ),
		),
	)
);

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

// Add custom control for Services Category with conditional visibility.
$wp_customize->add_control(new WP_Customize_Category_Dropdown_Control($wp_customize, 'resort_motel_services_category', array(
	'label'    => __('Select Services Category', 'resort-motel'),
	'section'  => 'resort_motel_service_section',
	'settings' => 'resort_motel_services_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('resort_motel_service_left_content_type')->value() === 'post';
	},
)));

for ( $resort_motel_i = 1; $resort_motel_i <= 6; $resort_motel_i++ ) {

	// Hotel Room Section - Select Post.
	$wp_customize->add_setting(
		'resort_motel_service_left_content_post_' . $resort_motel_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'resort_motel_service_left_content_post_' . $resort_motel_i,
		array(
			'label'           => esc_html__( 'Select Post ', 'resort-motel' ) . $resort_motel_i,
			'section'         => 'resort_motel_service_section',
			'settings'        => 'resort_motel_service_left_content_post_' . $resort_motel_i,
			'description'     => sprintf( esc_html__( 'Kindly :- Select a Post based on the category selected in the upper settings', 'resort-motel' ), $resort_motel_i ),
			'active_callback' => 'resort_motel_is_service_left_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => resort_motel_get_post_choices(),
		)
	);

	// Hotel Room Section - Select Page.
	$wp_customize->add_setting(
		'resort_motel_service_left_content_page_' . $resort_motel_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'resort_motel_service_left_content_page_' . $resort_motel_i,
		array(
			'label'           => esc_html__( 'Select Page ', 'resort-motel' ) . $resort_motel_i,
			'section'         => 'resort_motel_service_section',
			'settings'        => 'resort_motel_service_left_content_page_' . $resort_motel_i,
			'active_callback' => 'resort_motel_is_service_left_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => resort_motel_get_page_choices(),
		)
	);
}

// Hotel Room Section - Hotel Room Image.
$wp_customize->add_setting(
	'resort_motel_center_services_images',
	array(
		'sanitize_callback' => 'esc_url_raw',
	)
);

$wp_customize->add_control(
	new WP_Customize_Image_Control(
		$wp_customize,
		'resort_motel_center_services_images',
		array(
			'label'           => sprintf( esc_html__( 'Hotel Room Image', 'resort-motel' ), ),
			'section'         => 'resort_motel_service_section',
			'settings'        => 'resort_motel_center_services_images',
			'active_callback' => 'resort_motel_is_service_section_enabled',
		)
	)
);