<?php
/**
 * Adore Themes Customizer
 *
 * @package Nostalgic Blog
 *
 * Banner Section
 */

$wp_customize->add_section(
	'nostalgic_blog_banner_section',
	array(
		'title' => esc_html__( 'Banner Section', 'nostalgic-blog' ),
		'panel' => 'nostalgic_blog_frontpage_panel',
	)
);

// Banner section enable settings.
$wp_customize->add_setting(
	'nostalgic_blog_banner_section_enable',
	array(
		'default'           => false,
		'sanitize_callback' => 'nostalgic_blog_sanitize_checkbox',
	)
);
$wp_customize->add_control(
	new Nostalgic_Blog_Toggle_Checkbox_Custom_control(
		$wp_customize,
		'nostalgic_blog_banner_section_enable',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'nostalgic-blog' ),
			'type'     => 'checkbox',
			'settings' => 'nostalgic_blog_banner_section_enable',
			'section'  => 'nostalgic_blog_banner_section',
		)
	)
);

// Banner Section content type settings.
$wp_customize->add_setting(
	'nostalgic_blog_banner_section_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'nostalgic_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'nostalgic_blog_banner_section_content_type',
	array(
		'label'           => esc_html__( 'Content type:', 'nostalgic-blog' ),
		'description'     => esc_html__( 'Choose where you want to render the content from.', 'nostalgic-blog' ),
		'section'         => 'nostalgic_blog_banner_section',
		'type'            => 'select',
		'active_callback' => 'nostalgic_blog_if_banner_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'nostalgic-blog' ),
			'category' => esc_html__( 'Category', 'nostalgic-blog' ),
		),
	)
);

for ( $i = 1; $i <= 7; $i++ ) {
	// Banner Section post setting.
	$wp_customize->add_setting(
		'nostalgic_blog_banner_section_post_' . $i,
		array(
			'sanitize_callback' => 'nostalgic_blog_sanitize_dropdown_pages',
		)
	);

	$wp_customize->add_control(
		'nostalgic_blog_banner_section_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Post %d', 'nostalgic-blog' ), $i ),
			'section'         => 'nostalgic_blog_banner_section',
			'type'            => 'select',
			'choices'         => nostalgic_blog_get_post_choices(),
			'active_callback' => 'nostalgic_blog_banner_section_content_type_post_enabled',
		)
	);

}

// Banner Section category setting.
$wp_customize->add_setting(
	'nostalgic_blog_banner_section_category',
	array(
		'sanitize_callback' => 'nostalgic_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'nostalgic_blog_banner_section_category',
	array(
		'label'           => esc_html__( 'Category', 'nostalgic-blog' ),
		'section'         => 'nostalgic_blog_banner_section',
		'type'            => 'select',
		'choices'         => nostalgic_blog_get_post_cat_choices(),
		'active_callback' => 'nostalgic_blog_banner_section_content_type_category_enabled',
	)
);

/*========================Active Callback==============================*/
function nostalgic_blog_if_banner_section_enabled( $control ) {
	return $control->manager->get_setting( 'nostalgic_blog_banner_section_enable' )->value();
}
function nostalgic_blog_banner_section_content_type_post_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'nostalgic_blog_banner_section_content_type' )->value();
	return nostalgic_blog_if_banner_section_enabled( $control ) && ( 'post' === $content_type );
}
function nostalgic_blog_banner_section_content_type_category_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'nostalgic_blog_banner_section_content_type' )->value();
	return nostalgic_blog_if_banner_section_enabled( $control ) && ( 'category' === $content_type );
}
