<?php
/**
 * Slider Section Settings
 *
 * @package aster_portfolio
 */

// Add Slider Section
$wp_customize->add_section(
	'aster_portfolio_slider_section',
	array(
		'panel'    => 'aster_portfolio_front_page_options',
		'title'    => esc_html__( 'Slider Section', 'aster-portfolio' ),
		'priority' => 10,
	)
);

// Enable Slider Section
$wp_customize->add_setting(
	'aster_portfolio_enable_slider_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'aster_portfolio_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Aster_Portfolio_Toggle_Switch_Custom_Control(
		$wp_customize,
		'aster_portfolio_enable_slider_section',
		array(
			'label'    => esc_html__( 'Enable Slider Section', 'aster-portfolio' ),
			'section'  => 'aster_portfolio_slider_section',
			'settings' => 'aster_portfolio_enable_slider_section',
		)
	)
);

// Number of slider Posts to Show
$wp_customize->add_setting('aster_portfolio_slider_count',array(
	'default'	=> '',
	'sanitize_callback'	=> 'sanitize_text_field',
));
$wp_customize->add_control('aster_portfolio_slider_count',array(
	'label'	=> __('Number of sliders to show','aster-portfolio'),
	'description' => __('Add number and refresh tab','aster-portfolio'),
	'section'	=> 'aster_portfolio_slider_section',
	'type'		=> 'number',
	'active_callback' => 'aster_portfolio_is_slider_section_enabled',
	'input_attrs' => array(
		'step'             => 1,
		'min'              => 0,
		'max'              => 12,
	)
));

$aster_portfolio_slider_count = get_theme_mod( 'aster_portfolio_slider_count');

for ( $aster_portfolio_i = 1; $aster_portfolio_i <= $aster_portfolio_slider_count; $aster_portfolio_i++ ) {

	/* ---------- Subtitle ---------- */
	$wp_customize->add_setting( "aster_portfolio_slider_subtitle_{$aster_portfolio_i}", [
		'sanitize_callback' => 'sanitize_text_field',
	]);
	$wp_customize->add_control( "aster_portfolio_slider_subtitle_{$aster_portfolio_i}", [
		'label' => __( 'Slider Subtitle ', 'aster-portfolio' ) . $aster_portfolio_i,
		'section' => 'aster_portfolio_slider_section',
		'type' => 'text',
	]);

	/* ---------- Title ---------- */
	$wp_customize->add_setting( "aster_portfolio_slider_title_{$aster_portfolio_i}", [
		'sanitize_callback' => 'sanitize_text_field',
	]);
	$wp_customize->add_control( "aster_portfolio_slider_title_{$aster_portfolio_i}", [
		'label' => __( 'Slider Title ', 'aster-portfolio' ) . $aster_portfolio_i,
		'section' => 'aster_portfolio_slider_section',
		'type' => 'text',
	]);

	// Slider Title Image One
	$wp_customize->add_setting("aster_portfolio_slider_title_image_one_{$aster_portfolio_i}", [
		'sanitize_callback' => 'esc_url_raw',
		'default' => ''
	]);
	$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, "aster_portfolio_slider_title_image_one_{$aster_portfolio_i}", [
		'label' => __('Slider Title Image One', 'aster-portfolio'),
		'section' => 'aster_portfolio_slider_section',
		'settings' => "aster_portfolio_slider_title_image_one_{$aster_portfolio_i}"
	]));

	// Slider Title Image Two
	$wp_customize->add_setting("aster_portfolio_slider_title_image_two_{$aster_portfolio_i}", [
		'sanitize_callback' => 'esc_url_raw',
		'default' => ''
	]);
	$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, "aster_portfolio_slider_title_image_two_{$aster_portfolio_i}", [
		'label' => __('Slider Title Image Two', 'aster-portfolio'),
		'section' => 'aster_portfolio_slider_section',
		'settings' => "aster_portfolio_slider_title_image_two_{$aster_portfolio_i}"
	]));

	/* ---------- Image ---------- */
	$wp_customize->add_setting( "aster_portfolio_slider_image_{$aster_portfolio_i}", [
		'sanitize_callback' => 'esc_url_raw',
	]);
	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			"aster_portfolio_slider_image_{$aster_portfolio_i}",
			[
				'label' => __( 'Slider Image ', 'aster-portfolio' ) . $aster_portfolio_i,
				'section' => 'aster_portfolio_slider_section',
			]
		)
	);

	/* ---------- LEFT + RIGHT TEXT ---------- */
	$aster_portfolio_fields = [
		'expertise' => 'Expertise',
		'born'      => 'Born In',
		'birth'     => 'Date of Birth',
		'education' => 'Education',
		'award'     => 'Winning Award',
	];

	foreach ( $aster_portfolio_fields as $aster_portfolio_key => $aster_portfolio_label ) {

		$wp_customize->add_setting( "aster_portfolio_slider_{$aster_portfolio_key}_text_{$aster_portfolio_i}", [
			'sanitize_callback' => 'sanitize_text_field',
		]);

		$wp_customize->add_control( "aster_portfolio_slider_{$aster_portfolio_key}_text_{$aster_portfolio_i}", [
			'label' => $aster_portfolio_label . ' Text ' . $aster_portfolio_i,
			'section' => 'aster_portfolio_slider_section',
			'type' => 'text',
		]);

		$wp_customize->add_setting( "aster_portfolio_slider_{$aster_portfolio_key}_content_{$aster_portfolio_i}", [
			'sanitize_callback' => 'sanitize_text_field',
		]);

		$wp_customize->add_control( "aster_portfolio_slider_{$aster_portfolio_key}_content_{$aster_portfolio_i}", [
			'label' => $aster_portfolio_label . ' Content ' . $aster_portfolio_i,
			'section' => 'aster_portfolio_slider_section',
			'type' => 'text',
		]);
	}
}

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

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