<?php
/**
 * Banner Section
 *
 * @package News Revolution
 */

$wp_customize->add_section(
	'news_revolution_banner_section',
	array(
		'panel' => 'news_revolution_front_page_options',
		'title' => esc_html__( 'Banner Section', 'news-revolution' ),
	)
);

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

$wp_customize->add_control(
	new News_Revolution_Toggle_Switch_Custom_Control(
		$wp_customize,
		'news_revolution_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'news-revolution' ),
			'section'  => 'news_revolution_banner_section',
			'settings' => 'news_revolution_enable_banner_section',
		)
	)
);

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

// Banner Section - Main Banner Title.
$wp_customize->add_setting(
	'news_revolution_main_banner_title',
	array(
		'default'           => __( 'Main Banner', 'news-revolution' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'news_revolution_main_banner_title',
	array(
		'label'           => esc_html__( 'Main Banner Title Label', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_main_banner_title',
		'type'            => 'text',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
	)
);

// Banner Section - Autoplay Speed.
$wp_customize->add_setting(
	'news_revolution_main_banner_autoplay_speed',
	array(
		'default'           => 4000,
		'sanitize_callback' => 'news_revolution_sanitize_number_range',
	)
);

$wp_customize->add_control(
	'news_revolution_main_banner_autoplay_speed',
	array(
		'label'           => esc_html__( 'Autoplay Speed', 'news-revolution' ),
		'description'     => esc_html__( 'Note: Please input the valid number for autoplay and save. Number should be in milliseconds. Then refresh the page to see the change.', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_main_banner_autoplay_speed',
		'type'            => 'number',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
	)
);

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

$wp_customize->add_control(
	'news_revolution_main_banner_content_type',
	array(
		'label'           => esc_html__( 'Select Banner Content Type', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_main_banner_content_type',
		'type'            => 'select',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'news-revolution' ),
			'category' => esc_html__( 'Category', 'news-revolution' ),
		),
	)
);

for ( $i = 1; $i <= 3; $i++ ) {
	// Banner Section - Select Banner Slider Post.
	$wp_customize->add_setting(
		'news_revolution_main_banner_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'news_revolution_main_banner_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'news-revolution' ), $i ),
			'section'         => 'news_revolution_banner_section',
			'settings'        => 'news_revolution_main_banner_content_post_' . $i,
			'active_callback' => 'news_revolution_is_main_banner_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => news_revolution_get_post_choices(),
		)
	);

}

// Banner Section - Select Banner Slider Category.
$wp_customize->add_setting(
	'news_revolution_main_banner_content_category',
	array(
		'sanitize_callback' => 'news_revolution_sanitize_select',
	)
);

$wp_customize->add_control(
	'news_revolution_main_banner_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_main_banner_content_category',
		'active_callback' => 'news_revolution_is_main_banner_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => news_revolution_get_post_cat_choices(),
	)
);

// Banner Section - Main Banner Button Label.
$wp_customize->add_setting(
	'news_revolution_main_banner_button_label',
	array(
		'default'           => __( 'View All', 'news-revolution' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'news_revolution_main_banner_button_label',
	array(
		'label'           => esc_html__( 'Button Label', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_main_banner_button_label',
		'type'            => 'text',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
	)
);

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

$wp_customize->add_control(
	'news_revolution_main_banner_button_link',
	array(
		'label'           => esc_html__( 'Button Link', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_main_banner_button_link',
		'type'            => 'url',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
	)
);

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

$wp_customize->add_control(
	new News_Revolution_Customize_Horizontal_Line(
		$wp_customize,
		'news_revolution_banner_slider_horizontal_line',
		array(
			'section'         => 'news_revolution_banner_section',
			'settings'        => 'news_revolution_banner_slider_horizontal_line',
			'active_callback' => 'news_revolution_is_banner_section_enabled',
			'type'            => 'hr',
		)
	)
);

// Banner Section - Editor Choice Title.
$wp_customize->add_setting(
	'news_revolution_editor_choice_title',
	array(
		'default'           => __( 'Editor Choice', 'news-revolution' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'news_revolution_editor_choice_title',
	array(
		'label'           => esc_html__( 'Editor Choice Title', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_editor_choice_title',
		'type'            => 'text',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
	)
);

// Banner Section - Editor Choice Content Type.
$wp_customize->add_setting(
	'news_revolution_editor_choice_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'news_revolution_sanitize_select',
	)
);

$wp_customize->add_control(
	'news_revolution_editor_choice_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_editor_choice_content_type',
		'type'            => 'select',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'news-revolution' ),
			'category' => esc_html__( 'Category', 'news-revolution' ),
		),
	)
);

for ( $i = 1; $i <= 5; $i++ ) {
	// Banner Section - Select Post.
	$wp_customize->add_setting(
		'news_revolution_editor_choice_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'news_revolution_editor_choice_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'news-revolution' ), $i ),
			'section'         => 'news_revolution_banner_section',
			'settings'        => 'news_revolution_editor_choice_content_post_' . $i,
			'active_callback' => 'news_revolution_is_editor_picks_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => news_revolution_get_post_choices(),
		)
	);

}

// Banner Section - Select Category.
$wp_customize->add_setting(
	'news_revolution_editor_choice_content_category',
	array(
		'sanitize_callback' => 'news_revolution_sanitize_select',
	)
);

$wp_customize->add_control(
	'news_revolution_editor_choice_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_editor_choice_content_category',
		'active_callback' => 'news_revolution_is_editor_picks_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => news_revolution_get_post_cat_choices(),
	)
);

// Banner Section - Button Label.
$wp_customize->add_setting(
	'news_revolution_editor_choice_button_label',
	array(
		'default'           => __( 'View All', 'news-revolution' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'news_revolution_editor_choice_button_label',
	array(
		'label'           => esc_html__( 'Button Label', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_editor_choice_button_label',
		'type'            => 'text',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
	)
);

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

$wp_customize->add_control(
	'news_revolution_editor_choice_button_link',
	array(
		'label'           => esc_html__( 'Button Link', 'news-revolution' ),
		'section'         => 'news_revolution_banner_section',
		'settings'        => 'news_revolution_editor_choice_button_link',
		'type'            => 'url',
		'active_callback' => 'news_revolution_is_banner_section_enabled',
	)
);

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

$wp_customize->add_control(
	new News_Revolution_Customize_Horizontal_Line(
		$wp_customize,
		'news_revolution_advertisement_images_horizontal_line',
		array(
			'section'         => 'news_revolution_banner_section',
			'settings'        => 'news_revolution_advertisement_images_horizontal_line',
			'active_callback' => 'news_revolution_is_banner_section_enabled',
			'type'            => 'hr',
		)
	)
);

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

	// Banner Section - Advertisement Image.
	$wp_customize->add_setting(
		'news_revolution_advertisement_image_' . $i,
		array(
			'sanitize_callback' => 'news_revolution_sanitize_image',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'news_revolution_advertisement_image_' . $i,
			array(
				'label'           => sprintf( esc_html__( 'Advertisement %d', 'news-revolution' ), $i ),
				'section'         => 'news_revolution_banner_section',
				'settings'        => 'news_revolution_advertisement_image_' . $i,
				'active_callback' => 'news_revolution_is_banner_section_enabled',
			)
		)
	);

	// Banner Section - Advertisement Image URL.
	$wp_customize->add_setting(
		'news_revolution_advertisement_image_url_' . $i,
		array(
			'default'           => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	$wp_customize->add_control(
		'news_revolution_advertisement_image_url_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Advertisement URL %d', 'news-revolution' ), $i ),
			'section'         => 'news_revolution_banner_section',
			'settings'        => 'news_revolution_advertisement_image_url_' . $i,
			'type'            => 'url',
			'active_callback' => 'news_revolution_is_banner_section_enabled',
		)
	);

}
