<?php

/**
 * Banner Section
 *
 * @package resort_motel
 */

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

// Banner Section - Enable Section.
$wp_customize->add_setting(
	'resort_motel_enable_banner_section',
	array(
		'default'           => true,
		'sanitize_callback' => 'resort_motel_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Resort_Motel_Toggle_Switch_Custom_Control(
		$wp_customize,
		'resort_motel_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'resort-motel' ),
			'section'  => 'resort_motel_banner_section',
			'settings' => 'resort_motel_enable_banner_section',
		)
	)
);

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

// Add control for banner subtitle
$wp_customize->add_control( 'resort_motel_banner_subtitle', array(
    'label'    => __( 'Banner Subtitle', 'resort-motel' ),
    'section'  => 'resort_motel_banner_section', // Adjust this to your banner section
    'settings' => 'resort_motel_banner_subtitle',
	'active_callback' => 'resort_motel_is_banner_slider_section_enabled',
    'type'     => 'text',
) );

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

// Banner Section - Banner Slider Content Type.
$wp_customize->add_setting(
	'resort_motel_banner_slider_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'resort_motel_sanitize_select',
	)
);

$wp_customize->add_control(
	'resort_motel_banner_slider_content_type',
	array(
		'label'           => esc_html__( 'Select Banner Slider Content Type', 'resort-motel' ),
		'section'         => 'resort_motel_banner_section',
		'settings'        => 'resort_motel_banner_slider_content_type',
		'type'            => 'select',
		'active_callback' => 'resort_motel_is_banner_slider_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'resort-motel' ),
			'post' => esc_html__( 'Post', 'resort-motel' ),
		),
	)
);

// Banner Slider Category Setting.
$wp_customize->add_setting('resort_motel_banner_slider_category', array(
	'default'           => 'slider',
	'sanitize_callback' => 'sanitize_text_field',
));

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

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

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

	$wp_customize->add_control(
		'resort_motel_banner_slider_content_post_' . $resort_motel_i,
		array(
			/* translators: %d: Select Post Count. */
			'label'           => sprintf( esc_html__( 'Select Post %d', 'resort-motel' ), $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 ),
			'section'         => 'resort_motel_banner_section',
			'settings'        => 'resort_motel_banner_slider_content_post_' . $resort_motel_i,
			'active_callback' => 'resort_motel_is_banner_slider_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => resort_motel_get_post_choices(),
		)
	);

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

	$wp_customize->add_control(
		'resort_motel_banner_slider_content_page_' . $resort_motel_i,
		array(
			/* translators: %d: Select Page Count. */
			'label'           => sprintf( esc_html__( 'Select Page %d', 'resort-motel' ), $resort_motel_i ),
			'section'         => 'resort_motel_banner_section',
			'settings'        => 'resort_motel_banner_slider_content_page_' . $resort_motel_i,
			'active_callback' => 'resort_motel_is_banner_slider_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => resort_motel_get_page_choices(),
		)
	);

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

	$wp_customize->add_control(
		'resort_motel_banner_button_label_' . $resort_motel_i,
		array(
			/* translators: %d: Button Label Count. */
			'label'           => sprintf( esc_html__( 'Button Label %d', 'resort-motel' ), $resort_motel_i ),
			'section'         => 'resort_motel_banner_section',
			'settings'        => 'resort_motel_banner_button_label_' . $resort_motel_i,
			'type'            => 'text',
			'active_callback' => 'resort_motel_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'resort_motel_banner_button_link_' . $resort_motel_i,
		array(
			/* translators: %d: Button Link Count. */
			'label'           => sprintf( esc_html__( 'Button Link %d', 'resort-motel' ), $resort_motel_i ),
			'section'         => 'resort_motel_banner_section',
			'settings'        => 'resort_motel_banner_button_link_' . $resort_motel_i,
			'type'            => 'url',
			'active_callback' => 'resort_motel_is_banner_slider_section_enabled',
		)
	);
}

// Banner Button Label Color
$wp_customize->add_setting(
	'resort_motel_banner_btn_color',
	array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'resort_motel_banner_btn_color',array(
			'label' => __('Banner Button Label Color','resort-motel'),
			'section' => 'resort_motel_banner_section',
			'settings' => 'resort_motel_banner_btn_color',
			'active_callback' => 'resort_motel_is_banner_slider_section_enabled',
		)
	)
);

// Banner Button Background Color
$wp_customize->add_setting('resort_motel_banner_btn_bg_color',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'resort_motel_banner_btn_bg_color',array(
			'label' => __('Banner Button Background Color','resort-motel'),
			'section' => 'resort_motel_banner_section',
			'settings' => 'resort_motel_banner_btn_bg_color',
			'active_callback' => 'resort_motel_is_banner_slider_section_enabled',
		)
	)
);
// Banner Button Border Color
$wp_customize->add_setting(
	'resort_motel_banner_btn_border_color',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'resort_motel_banner_btn_border_color',array(
			'label' => __('Banner Button Border Color','resort-motel'),
			'section' => 'resort_motel_banner_section',
			'settings' => 'resort_motel_banner_btn_border_color',
			'active_callback' => 'resort_motel_is_banner_slider_section_enabled',
		)
	)
);
