<?php

/**
 * About Us Section
 *
 * @package construction_engineer
 */

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

// About Us Section - Enable Section.
$wp_customize->add_setting(
	'construction_engineer_enable_service_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_service_section',
		array(
			'label'    => esc_html__( 'Enable About Us Section', 'construction-engineer' ),
			'section'  => 'construction_engineer_services_section',
			'settings' => 'construction_engineer_enable_service_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'construction_engineer_trending_product_heading',
	array(
		'label'           => esc_html__( 'Heading', 'construction-engineer' ),
		'section'         => 'construction_engineer_services_section',
		'settings'        => 'construction_engineer_trending_product_heading',
		'type'            => 'text',
		'active_callback' => 'construction_engineer_is_service_section_enabled',
	)
);

// About Us Section - Content Type.
$wp_customize->add_setting(
	'construction_engineer_service_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'construction_engineer_sanitize_select',
	)
);

$wp_customize->add_control(
	'construction_engineer_service_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'construction-engineer' ),
		'section'         => 'construction_engineer_services_section',
		'settings'        => 'construction_engineer_service_content_type',
		'type'            => 'select',
		'active_callback' => 'construction_engineer_is_service_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'construction-engineer' ),
			'post' => esc_html__( 'Post', 'construction-engineer' ),
		),
	)
);

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

// Add custom control for Services Category with conditional visibility.
$wp_customize->add_control(new Construction_Engineer_Customize_Category_Dropdown_Control($wp_customize, 'construction_engineer_services_category', array(
	'label'    => __('Select Services Category', 'construction-engineer'),
	'section'  => 'construction_engineer_services_section',
	'settings' => 'construction_engineer_services_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('construction_engineer_service_content_type')->value() === 'post';
	},
)));

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

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

	$wp_customize->add_control(
		'construction_engineer_service_content_post_' . $construction_engineer_i,
		array(
			'label'           => esc_html__( 'Select Post ', '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_services_section',
			'settings'        => 'construction_engineer_service_content_post_' . $construction_engineer_i,
			'active_callback' => 'construction_engineer_is_service_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => construction_engineer_get_post_choices(),
		)
	);

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

	$wp_customize->add_control(
		'construction_engineer_service_content_page_' . $construction_engineer_i,
		array(
			'label'           => esc_html__( 'Select Page ', 'construction-engineer' ) . $construction_engineer_i,
			'section'         => 'construction_engineer_services_section',
			'settings'        => 'construction_engineer_service_content_page_' . $construction_engineer_i,
			'active_callback' => 'construction_engineer_is_service_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => construction_engineer_get_page_choices(),
		)
	);
}

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

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

	$wp_customize->add_control(
		'construction_engineer_trending_product_content' . $construction_engineer_i,
		array(
			'label'           => esc_html__( 'Featured Heading ', 'construction-engineer' )  . $construction_engineer_i,
			'section'         => 'construction_engineer_services_section',
			'settings'        => 'construction_engineer_trending_product_content'. $construction_engineer_i,
			'type'            => 'text',
			'active_callback' => 'construction_engineer_is_service_section_enabled' ,
		)
	);

}

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

$wp_customize->add_control(
	'construction_engineer_product_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_services_section'
	)
);