<?php
/**
 * Banner Section
 *
 * @package Majestic Blog
 */

$wp_customize->add_section(
	'majestic_blog_banner_section',
	array(
		'panel' => 'majestic_blog_front_page_options',
		'title' => esc_html__( 'Banner Section', 'majestic-blog' ),
	)
);

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

$wp_customize->add_control(
	new Majestic_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'majestic_blog_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'majestic-blog' ),
			'section'  => 'majestic_blog_banner_section',
			'settings' => 'majestic_blog_enable_banner_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'majestic_blog_banner_slider_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'majestic-blog' ),
		'section'         => 'majestic_blog_banner_section',
		'settings'        => 'majestic_blog_banner_slider_content_type',
		'type'            => 'select',
		'active_callback' => 'majestic_blog_is_banner_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'majestic-blog' ),
			'category' => esc_html__( 'Category', 'majestic-blog' ),
		),
	)
);

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

$wp_customize->add_control(
	'majestic_blog_banner_slider_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'majestic-blog' ),
		'section'         => 'majestic_blog_banner_section',
		'settings'        => 'majestic_blog_banner_slider_content_category',
		'active_callback' => 'majestic_blog_is_banner_slider_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => majestic_blog_get_post_cat_choices(),
	)
);

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

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

	$wp_customize->add_control(
		'majestic_blog_banner_slider_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'majestic-blog' ), $i ),
			'section'         => 'majestic_blog_banner_section',
			'settings'        => 'majestic_blog_banner_slider_content_post_' . $i,
			'active_callback' => 'majestic_blog_is_banner_slider_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => majestic_blog_get_post_choices(),
		)
	);

}

// Banner Section - Read More Button.
$wp_customize->add_setting(
	'majestic_blog_banner_read_more_button',
	array(
		'default'           => __( 'View the post', 'majestic-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'majestic_blog_banner_read_more_button',
	array(
		'label'           => esc_html__( 'Read More Button Label', 'majestic-blog' ),
		'section'         => 'majestic_blog_banner_section',
		'settings'        => 'majestic_blog_banner_read_more_button',
		'type'            => 'text',
		'active_callback' => 'majestic_blog_is_banner_section_enabled',
	)
);

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

$wp_customize->add_control(
	new Majestic_Blog_Customize_Horizontal_Line(
		$wp_customize,
		'majestic_blog_banner_horizontal_line',
		array(
			'section'         => 'majestic_blog_banner_section',
			'settings'        => 'majestic_blog_banner_horizontal_line',
			'active_callback' => 'majestic_blog_is_banner_section_enabled',
			'type'            => 'hr',
		)
	)
);

// Banner Section - Section Title.
$wp_customize->add_setting(
	'majestic_blog_banner_editor_choice_title',
	array(
		'default'           => __( 'Editor Choice', 'majestic-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'majestic_blog_banner_editor_choice_title',
	array(
		'label'           => esc_html__( 'Section Title', 'majestic-blog' ),
		'section'         => 'majestic_blog_banner_section',
		'settings'        => 'majestic_blog_banner_editor_choice_title',
		'type'            => 'text',
		'active_callback' => 'majestic_blog_is_banner_section_enabled',
	)
);

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

$wp_customize->add_control(
	'majestic_blog_banner_editor_choice_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'majestic-blog' ),
		'section'         => 'majestic_blog_banner_section',
		'settings'        => 'majestic_blog_banner_editor_choice_content_type',
		'type'            => 'select',
		'active_callback' => 'majestic_blog_is_banner_section_enabled',
		'choices'         => array(
			'post'   => esc_html__( 'Post', 'majestic-blog' ),
			'recent' => esc_html__( 'Recent', 'majestic-blog' ),
		),
	)
);

// Banner Section - Select Editor Choice Category.
$wp_customize->add_setting(
	'majestic_blog_banner_editor_choice_content_category',
	array(
		'sanitize_callback' => 'majestic_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'majestic_blog_banner_editor_choice_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'majestic-blog' ),
		'section'         => 'majestic_blog_banner_section',
		'settings'        => 'majestic_blog_banner_editor_choice_content_category',
		'active_callback' => 'majestic_blog_is_banner_editor_choice_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => majestic_blog_get_post_cat_choices(),
	)
);

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

	// Banner Section - Select Banner Editor Choice Post.
	$wp_customize->add_setting(
		'majestic_blog_banner_editor_choice_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'majestic_blog_banner_editor_choice_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'majestic-blog' ), $i ),
			'section'         => 'majestic_blog_banner_section',
			'settings'        => 'majestic_blog_banner_editor_choice_content_post_' . $i,
			'active_callback' => 'majestic_blog_is_banner_editor_choice_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => majestic_blog_get_post_choices(),
		)
	);

}
