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

$wp_customize->add_section(
	'zenith_blog_banner_section',
	array(
		'panel' => 'zenith_blog_front_page_options',
		'title' => esc_html__( 'Banner Section', 'zenith-blog' ),
	)
);

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

$wp_customize->add_control(
	new Zenith_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'zenith_blog_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'zenith-blog' ),
			'section'  => 'zenith_blog_banner_section',
			'settings' => 'zenith_blog_enable_banner_section',
			'priority' => 10,
		)
	)
);

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

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

$wp_customize->add_control(
	'zenith_blog_banner_slider_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'zenith-blog' ),
		'section'         => 'zenith_blog_banner_section',
		'settings'        => 'zenith_blog_banner_slider_content_type',
		'type'            => 'select',
		'active_callback' => 'zenith_blog_is_banner_section_enabled',
		'priority'        => 20,
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'zenith-blog' ),
			'category' => esc_html__( 'Category', 'zenith-blog' ),
		),
	)
);

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

	$wp_customize->add_control(
		'zenith_blog_banner_slider_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'zenith-blog' ), $i ),
			'section'         => 'zenith_blog_banner_section',
			'settings'        => 'zenith_blog_banner_slider_content_post_' . $i,
			'active_callback' => 'zenith_blog_is_banner_slider_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => zenith_blog_get_post_choices(),
			'priority'        => 30,
		)
	);

}

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

$wp_customize->add_control(
	'zenith_blog_banner_slider_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'zenith-blog' ),
		'section'         => 'zenith_blog_banner_section',
		'settings'        => 'zenith_blog_banner_slider_content_category',
		'active_callback' => 'zenith_blog_is_banner_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => zenith_blog_get_post_cat_choices(),
		'priority'        => 40,
	)
);
