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

$wp_customize->add_section(
	'corporaze_banner_section',
	array(
		'panel'    => 'corporaze_front_page_options',
		'title'    => esc_html__( 'Banner Slider Section', 'corporaze' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Corporaze_Toggle_Switch_Custom_Control(
		$wp_customize,
		'corporaze_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'corporaze' ),
			'section'  => 'corporaze_banner_section',
			'settings' => 'corporaze_enable_banner_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'corporaze_banner_content',
	array(
		'label'           => esc_html__( 'Select Content Type', 'corporaze' ),
		'section'         => 'corporaze_banner_section',
		'settings'        => 'corporaze_banner_content',
		'type'            => 'select',
		'active_callback' => 'corporaze_is_banner_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'corporaze' ),
			'post' => esc_html__( 'Post', 'corporaze' ),
		),
	)
);

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

	// Banner Section - Content Type Post.
	$wp_customize->add_setting(
		'corporaze_banner_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'corporaze_banner_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_banner_section',
			'settings'        => 'corporaze_banner_content_post_' . $i,
			'active_callback' => 'corporaze_is_banner_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => corporaze_get_post_choices(),
		)
	);

	// Banner Section - Content Type Page.
	$wp_customize->add_setting(
		'corporaze_banner_content_page_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'corporaze_banner_content_page_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Page %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_banner_section',
			'settings'        => 'corporaze_banner_content_page_' . $i,
			'active_callback' => 'corporaze_is_banner_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => corporaze_get_page_choices(),
		)
	);

	// Banner Section - Button Label.
	$wp_customize->add_setting(
		'corporaze_banner_button_label' . $i,
		array(
			'default'           => __( 'Read More', 'corporaze' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'corporaze_banner_button_label' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Button Label %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_banner_section',
			'settings'        => 'corporaze_banner_button_label' . $i,
			'type'            => 'text',
			'active_callback' => 'corporaze_is_banner_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'corporaze_banner_button_link' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Button Link %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_banner_section',
			'settings'        => 'corporaze_banner_button_link' . $i,
			'type'            => 'url',
			'active_callback' => 'corporaze_is_banner_section_enabled',
		)
	);

	// Banner Section - Video Link.
	$wp_customize->add_setting(
		'corporaze_banner_video_url' . $i,
		array(
			'default'           => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	$wp_customize->add_control(
		'corporaze_banner_video_url' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Video Link %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_banner_section',
			'settings'        => 'corporaze_banner_video_url' . $i,
			'type'            => 'url',
			'active_callback' => 'corporaze_is_banner_section_enabled',
		)
	);

	// Banner Section - Video Label.
	$wp_customize->add_setting(
		'corporaze_banner_video_text' . $i,
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'corporaze_banner_video_text' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Video Text %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_banner_section',
			'settings'        => 'corporaze_banner_video_text' . $i,
			'type'            => 'text',
			'active_callback' => 'corporaze_is_banner_section_enabled',
		)
	);

	// Banner Section - Horizontal Line.
	$wp_customize->add_setting(
		'corporaze_banner_horizontal_line' . $i,
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		new Corporaze_Customize_Horizontal_Line(
			$wp_customize,
			'corporaze_banner_horizontal_line' . $i,
			array(
				'section'         => 'corporaze_banner_section',
				'settings'        => 'corporaze_banner_horizontal_line' . $i,
				'active_callback' => 'corporaze_is_banner_section_enabled',
				'type'            => 'hr',
			)
		)
	);

}
