<?php
/**
 * Banner Section
 *
 * @package wheel_alignment_service
 */

$wp_customize->add_section(
	'wheel_alignment_service_banner_section',
	array(
		'panel'    => 'wheel_alignment_service_front_page_options',
		'title'    => esc_html__( 'Banner Section', 'wheel-alignment-service' ),
		'priority' => 10,
	)
);

// Banner Section - Enable Section.
$wp_customize->add_setting(
	'wheel_alignment_service_enable_banner_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'wheel_alignment_service_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Wheel_Alignment_Service_Toggle_Switch_Custom_Control(
		$wp_customize,
		'wheel_alignment_service_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'wheel-alignment-service' ),
			'section'  => 'wheel_alignment_service_banner_section',
			'settings' => 'wheel_alignment_service_enable_banner_section',
		)
	)
);

$wp_customize->add_setting( 'wheel_alignment_service_banner_heading', array(
    'default'           => '',
    'transport'         => 'refresh',
    'sanitize_callback' => 'sanitize_text_field',
) );

// Add the control for the new heading
$wp_customize->add_control( 'wheel_alignment_service_banner_heading', array(
    'label'    => __( 'Banner Heading', 'wheel-alignment-service' ),
    'section'  => 'wheel_alignment_service_banner_section',
    'settings' => 'wheel_alignment_service_banner_heading',
    'type'     => 'text',
	'active_callback' => 'wheel_alignment_service_is_banner_slider_section_enabled',
) );

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

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

$wp_customize->add_control(
	'wheel_alignment_service_banner_slider_content_type',
	array(
		'label'           => esc_html__( 'Select Banner Slider Content Type', 'wheel-alignment-service' ),
		'section'         => 'wheel_alignment_service_banner_section',
		'settings'        => 'wheel_alignment_service_banner_slider_content_type',
		'type'            => 'select',
		'active_callback' => 'wheel_alignment_service_is_banner_slider_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'wheel-alignment-service' ),
			'post' => esc_html__( 'Post', 'wheel-alignment-service' ),
		),
	)
);

// Banner Slider Category Setting.
$wp_customize->add_setting('wheel_alignment_service_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 Wheel_Alignment_Service_Customize_Category_Dropdown_Control($wp_customize, 'wheel_alignment_service_banner_slider_category', array(
	'label'    => __('Select Banner Category', 'wheel-alignment-service'),
	'section'  => 'wheel_alignment_service_banner_section',
	'settings' => 'wheel_alignment_service_banner_slider_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('wheel_alignment_service_banner_slider_content_type')->value() === 'post';
	},
)));


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

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

	$wp_customize->add_control(
		'wheel_alignment_service_banner_slider_content_post_' . $wheel_alignment_service_i,
		array(
			/* translators: %d: Post Count. */
			'label'           => sprintf( esc_html__( 'Select Post %d', 'wheel-alignment-service' ), $wheel_alignment_service_i ),
			'description'     => sprintf( esc_html__( 'Kindly :- Select a Post based on the category selected in the upper settings', 'wheel-alignment-service' ), $wheel_alignment_service_i ),
			'section'         => 'wheel_alignment_service_banner_section',
			'settings'        => 'wheel_alignment_service_banner_slider_content_post_' . $wheel_alignment_service_i,
			'active_callback' => 'wheel_alignment_service_is_banner_slider_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => wheel_alignment_service_get_post_choices(),
		)
	);

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

	$wp_customize->add_control(
		'wheel_alignment_service_banner_slider_content_page_' . $wheel_alignment_service_i,
		array(
			/* translators: %d: Page Count. */
			'label'           => sprintf( esc_html__( 'Select Page %d', 'wheel-alignment-service' ), $wheel_alignment_service_i ),
			'section'         => 'wheel_alignment_service_banner_section',
			'settings'        => 'wheel_alignment_service_banner_slider_content_page_' . $wheel_alignment_service_i,
			'active_callback' => 'wheel_alignment_service_is_banner_slider_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => wheel_alignment_service_get_page_choices(),
		)
	);

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

	$wp_customize->add_control(
		'wheel_alignment_service_banner_button_label_' . $wheel_alignment_service_i,
		array(
			/* translators: %d: Button Label Count. */
			'label'           => sprintf( esc_html__( 'Button Label %d', 'wheel-alignment-service' ), $wheel_alignment_service_i ),
			'section'         => 'wheel_alignment_service_banner_section',
			'settings'        => 'wheel_alignment_service_banner_button_label_' . $wheel_alignment_service_i,
			'type'            => 'text',
			'active_callback' => 'wheel_alignment_service_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'wheel_alignment_service_banner_button_link_' . $wheel_alignment_service_i,
		array(
			/* translators: %d: Button Link Count. */
			'label'           => sprintf( esc_html__( 'Button Link %d', 'wheel-alignment-service' ), $wheel_alignment_service_i ),
			'section'         => 'wheel_alignment_service_banner_section',
			'settings'        => 'wheel_alignment_service_banner_button_link_' . $wheel_alignment_service_i,
			'type'            => 'url',
			'active_callback' => 'wheel_alignment_service_is_banner_slider_section_enabled',
		)
	);
}

$wp_customize->add_setting( 'wheel_alignment_service_banner_side_heading', array(
    'default'           => 'WHEELALLIGNMENT',
    'transport'         => 'refresh',
    'sanitize_callback' => 'sanitize_text_field',
) );

// Add the control for the new heading
$wp_customize->add_control( 'wheel_alignment_service_banner_side_heading', array(
    'label'    => __( 'Add Banner Side Content', 'wheel-alignment-service' ),
    'section'  => 'wheel_alignment_service_banner_section',
    'settings' => 'wheel_alignment_service_banner_side_heading',
    'type'     => 'text',
	'active_callback' => 'wheel_alignment_service_is_banner_slider_section_enabled',
) );

// Slider Button Label Color
$wp_customize->add_setting('wheel_alignment_service_slider_btn_color',array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'wheel_alignment_service_slider_btn_color',array(
			'label'           => __('Slider Button Label Color', 'wheel-alignment-service'),
			'section'         => 'wheel_alignment_service_banner_section',
			'settings'        => 'wheel_alignment_service_slider_btn_color',
			'active_callback' => 'wheel_alignment_service_is_banner_slider_section_enabled',
		)
	)
);
// Slider Button Background Color
$wp_customize->add_setting('wheel_alignment_service_slider_btn_bg_color',array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'wheel_alignment_service_slider_btn_bg_color',array(
			'label'           => __('Slider Button Background Color', 'wheel-alignment-service'),
			'section'         => 'wheel_alignment_service_banner_section',
			'settings'        => 'wheel_alignment_service_slider_btn_bg_color',
			'active_callback' => 'wheel_alignment_service_is_banner_slider_section_enabled',
		)
	)
);

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

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