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

$wp_customize->add_section(
	'cosmic_blog_banner_section',
	array(
		'panel'    => 'cosmic_blog_front_page_options',
		'title'    => esc_html__( 'Banner Section', 'cosmic-blog' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Cosmic_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'cosmic_blog_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'cosmic-blog' ),
			'section'  => 'cosmic_blog_banner_section',
			'settings' => 'cosmic_blog_enable_banner_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'cosmic_blog_banner_slider_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'cosmic-blog' ),
		'section'         => 'cosmic_blog_banner_section',
		'settings'        => 'cosmic_blog_banner_slider_content_type',
		'type'            => 'select',
		'active_callback' => 'cosmic_blog_is_banner_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'cosmic-blog' ),
			'category' => esc_html__( 'Category', 'cosmic-blog' ),
		),
	)
);

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

$wp_customize->add_control(
	'cosmic_blog_banner_slider_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'cosmic-blog' ),
		'section'         => 'cosmic_blog_banner_section',
		'settings'        => 'cosmic_blog_banner_slider_content_category',
		'active_callback' => 'cosmic_blog_is_banner_slider_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => cosmic_blog_get_post_cat_choices(),
	)
);

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

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

	$wp_customize->add_control(
		'cosmic_blog_banner_slider_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'cosmic-blog' ), $i ),
			'section'         => 'cosmic_blog_banner_section',
			'settings'        => 'cosmic_blog_banner_slider_content_post_' . $i,
			'active_callback' => 'cosmic_blog_is_banner_slider_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => cosmic_blog_get_post_choices(),
		)
	);

}
