<?php

/**
 * Banner Section
 *
 * @package construction_engineer
 */

$wp_customize->add_section(
	'construction_engineer_banner_section',
	array(
		'panel'    => 'construction_engineer_front_page_options',
		'title'    => esc_html__( 'Banner Section', 'construction-engineer' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Construction_Engineer_Toggle_Switch_Custom_Control(
		$wp_customize,
		'construction_engineer_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'construction-engineer' ),
			'section'  => 'construction_engineer_banner_section',
			'settings' => 'construction_engineer_enable_banner_section',
		)
	)
);

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


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

$wp_customize->add_control(
	'construction_engineer_banner_slider_content_type',
	array(
		'label'           => esc_html__( 'Select Banner Slider Content Type', 'construction-engineer' ),
		'section'         => 'construction_engineer_banner_section',
		'settings'        => 'construction_engineer_banner_slider_content_type',
		'type'            => 'select',
		'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'construction-engineer' ),
			'post' => esc_html__( 'Post', 'construction-engineer' ),
		),
	)
);

// Banner Slider Category Setting.
$wp_customize->add_setting('construction_engineer_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 Construction_Engineer_Customize_Category_Dropdown_Control($wp_customize, 'construction_engineer_banner_slider_category', array(
	'label'    => __('Select Banner Slider Category', 'construction-engineer'),
	'section'  => 'construction_engineer_banner_section',
	'settings' => 'construction_engineer_banner_slider_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('construction_engineer_banner_slider_content_type')->value() === 'post';
	},
)));


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

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

	$wp_customize->add_control(
		'construction_engineer_banner_slider_content_post_' . $construction_engineer_i,
		array(
			/* translators: %d: Select Post Count. */
			'label'           => sprintf( esc_html__( 'Select Post %d', 'construction-engineer' ), $construction_engineer_i ),
			'description'     => sprintf( esc_html__( 'Kindly :- Select a Post based on the category selected in the upper settings', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_slider_content_post_' . $construction_engineer_i,
			'active_callback' => 'construction_engineer_is_banner_slider_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => construction_engineer_get_post_choices(),
		)
	);

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

	$wp_customize->add_control(
		'construction_engineer_banner_slider_content_page_' . $construction_engineer_i,
		array(
			/* translators: %d: Select Page Count. */
			'label'           => sprintf( esc_html__( 'Select Page %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_slider_content_page_' . $construction_engineer_i,
			'active_callback' => 'construction_engineer_is_banner_slider_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => construction_engineer_get_page_choices(),
		)
	);

	// Banner Section - Short Label.
	$wp_customize->add_setting(
		'construction_engineer_banner_short_heading_1' . $construction_engineer_i,
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'construction_engineer_banner_short_heading_1' . $construction_engineer_i,
		array(
			/* translators: %d: Services Heading 1 Count. */
			'label'           => sprintf( esc_html__( 'Banner Services Heading 1 %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_short_heading_1' . $construction_engineer_i,
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
			'type'            => 'text',
		)
	);

	// Banner Section - Short Label.
	$wp_customize->add_setting(
		'construction_engineer_banner_short_heading_2' . $construction_engineer_i,
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'construction_engineer_banner_short_heading_2' . $construction_engineer_i,
		array(
			/* translators: %d: Services Heading 2 Count. */
			'label'           => sprintf( esc_html__( 'Banner Services Heading 2 %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_short_heading_2' . $construction_engineer_i,
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
			'type'            => 'text',
		)
	);

	// Banner Section - Short Label.
	$wp_customize->add_setting(
		'construction_engineer_banner_short_heading_3' . $construction_engineer_i,
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'construction_engineer_banner_short_heading_3' . $construction_engineer_i,
		array(
			/* translators: %d: Services Heading 3 Count. */
			'label'           => sprintf( esc_html__( 'Banner Services Heading 3 %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_short_heading_3' . $construction_engineer_i,
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
			'type'            => 'text',
		)
	);

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

	$wp_customize->add_control(
		'construction_engineer_banner_button_label_' . $construction_engineer_i,
		array(
			/* translators: %d: Button Label 1 Count. */
			'label'           => sprintf( esc_html__( 'Button Label 1 %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_button_label_' . $construction_engineer_i,
			'type'            => 'text',
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'construction_engineer_banner_button_link_' . $construction_engineer_i,
		array(
			/* translators: %d: Button Link 1 Count. */
			'label'           => sprintf( esc_html__( 'Button Link 1 %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_button_link_' . $construction_engineer_i,
			'type'            => 'url',
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'construction_engineer_banner_second_button_label_' . $construction_engineer_i,
		array(
			/* translators: %d: Button Label 2 Count. */
			'label'           => sprintf( esc_html__( 'Button Label 2 %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_second_button_label_' . $construction_engineer_i,
			'type'            => 'text',
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'construction_engineer_banner_second_button_link_' . $construction_engineer_i,
		array(
			/* translators: %d: Button Link 2 Count. */
			'label'           => sprintf( esc_html__( 'Button Link 2 %d', 'construction-engineer' ), $construction_engineer_i ),
			'section'         => 'construction_engineer_banner_section',
			'settings'        => 'construction_engineer_banner_second_button_link_' . $construction_engineer_i,
			'type'            => 'url',
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		)
	);
}

// Banner Button Label Color
$wp_customize->add_setting(
	'construction_engineer_banner_btn_color',
	array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'construction_engineer_banner_btn_color',array(
			'label' => __('Banner Button Label Color','construction-engineer'),
			'section' => 'construction_engineer_banner_section',
			'settings' => 'construction_engineer_banner_btn_color',
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		)
	)
);

// Banner Button Background Color
$wp_customize->add_setting('construction_engineer_banner_btn_bg_color',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'construction_engineer_banner_btn_bg_color',array(
			'label' => __('Banner Button Background Color','construction-engineer'),
			'section' => 'construction_engineer_banner_section',
			'settings' => 'construction_engineer_banner_btn_bg_color',
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		)
	)
);
// Banner Button Border Color
$wp_customize->add_setting(
	'construction_engineer_banner_btn_border_color',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	)
);
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'construction_engineer_banner_btn_border_color',array(
			'label' => __('Banner Button Border Color','construction-engineer'),
			'section' => 'construction_engineer_banner_section',
			'settings' => 'construction_engineer_banner_btn_border_color',
			'active_callback' => 'construction_engineer_is_banner_slider_section_enabled',
		)
	)
);


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

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