<?php
/**
 * Adore Themes Customizer
 *
 * @package Hot News
 *
 * Banner Section
 */

$wp_customize->add_section(
	'hot_news_banner_section',
	array(
		'title'    => esc_html__( 'Banner Section', 'hot-news' ),
		'panel'    => 'hot_news_frontpage_panel',
		'priority' => 20,
	)
);

// Banner enable setting.
$wp_customize->add_setting(
	'hot_news_banner_section_enable',
	array(
		'default'           => false,
		'sanitize_callback' => 'hot_news_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	new Hot_News_Toggle_Checkbox_Custom_control(
		$wp_customize,
		'hot_news_banner_section_enable',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'hot-news' ),
			'type'     => 'checkbox',
			'settings' => 'hot_news_banner_section_enable',
			'section'  => 'hot_news_banner_section',
		)
	)
);

// Banner Section Sub Heading.
$wp_customize->add_setting(
	'hot_news_banner_section_sub_heading',
	array(
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	new Hot_News_Sub_Section_Heading_Custom_Control(
		$wp_customize,
		'hot_news_banner_section_sub_heading',
		array(
			'label'           => esc_html__( 'Banner News Section', 'hot-news' ),
			'settings'        => 'hot_news_banner_section_sub_heading',
			'section'         => 'hot_news_banner_section',
			'active_callback' => 'hot_news_if_banner_enabled',
		)
	)
);

// Banner News title settings.
$wp_customize->add_setting(
	'hot_news_banner_news_title',
	array(
		'default'           => __( 'Main News', 'hot-news' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'hot_news_banner_news_title',
	array(
		'label'           => esc_html__( 'Title', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'active_callback' => 'hot_news_if_banner_enabled',
	)
);

// Banner news content type settings.
$wp_customize->add_setting(
	'hot_news_banner_news_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'hot_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'hot_news_banner_news_content_type',
	array(
		'label'           => esc_html__( 'Banner News Content type:', 'hot-news' ),
		'description'     => esc_html__( 'Choose where you want to render the content from.', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'type'            => 'select',
		'active_callback' => 'hot_news_if_banner_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'hot-news' ),
			'category' => esc_html__( 'Category', 'hot-news' ),
		),
	)
);

for ( $i = 1; $i <= 3; $i++ ) {
	// banner post setting.
	$wp_customize->add_setting(
		'hot_news_banner_news_post_' . $i,
		array(
			'sanitize_callback' => 'hot_news_sanitize_dropdown_pages',
		)
	);

	$wp_customize->add_control(
		'hot_news_banner_news_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Post %d', 'hot-news' ), $i ),
			'section'         => 'hot_news_banner_section',
			'type'            => 'select',
			'choices'         => hot_news_get_post_choices(),
			'active_callback' => 'hot_news_banner_news_content_type_post_enabled',
		)
	);

}

// banner category setting.
$wp_customize->add_setting(
	'hot_news_banner_news_category',
	array(
		'sanitize_callback' => 'hot_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'hot_news_banner_news_category',
	array(
		'label'           => esc_html__( 'Category', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'type'            => 'select',
		'choices'         => hot_news_get_post_cat_choices(),
		'active_callback' => 'hot_news_banner_news_content_type_category_enabled',
	)
);

// Featured Posts Sub Heading.
$wp_customize->add_setting(
	'hot_news_featured_posts_sub_heading',
	array(
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	new Hot_News_Sub_Section_Heading_Custom_Control(
		$wp_customize,
		'hot_news_featured_posts_sub_heading',
		array(
			'label'           => esc_html__( 'Featured Posts Section', 'hot-news' ),
			'settings'        => 'hot_news_featured_posts_sub_heading',
			'section'         => 'hot_news_banner_section',
			'active_callback' => 'hot_news_if_banner_enabled',
		)
	)
);

// banner featured posts title settings.
$wp_customize->add_setting(
	'hot_news_featured_news_title',
	array(
		'default'           => __( 'Featured News', 'hot-news' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'hot_news_featured_news_title',
	array(
		'label'           => esc_html__( 'Title', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'active_callback' => 'hot_news_if_banner_enabled',
	)
);

// banner featured posts content type settings.
$wp_customize->add_setting(
	'hot_news_featured_posts_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'hot_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'hot_news_featured_posts_content_type',
	array(
		'label'           => esc_html__( 'Featured Posts Content type:', 'hot-news' ),
		'description'     => esc_html__( 'Choose where you want to render the content from.', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'settings'        => 'hot_news_featured_posts_content_type',
		'type'            => 'select',
		'active_callback' => 'hot_news_if_banner_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'hot-news' ),
			'category' => esc_html__( 'Category', 'hot-news' ),
		),
	)
);

for ( $i = 1; $i <= 2; $i++ ) {
	// Featured Posts post setting.
	$wp_customize->add_setting(
		'hot_news_featured_posts_post_' . $i,
		array(
			'sanitize_callback' => 'hot_news_sanitize_dropdown_pages',
		)
	);

	$wp_customize->add_control(
		'hot_news_featured_posts_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Post %d', 'hot-news' ), $i ),
			'section'         => 'hot_news_banner_section',
			'type'            => 'select',
			'choices'         => hot_news_get_post_choices(),
			'active_callback' => 'hot_news_featured_posts_section_content_type_post_enabled',
		)
	);

}

// Featured Posts category setting.
$wp_customize->add_setting(
	'hot_news_featured_posts_category',
	array(
		'sanitize_callback' => 'hot_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'hot_news_featured_posts_category',
	array(
		'label'           => esc_html__( 'Category', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'type'            => 'select',
		'choices'         => hot_news_get_post_cat_choices(),
		'active_callback' => 'hot_news_featured_posts_section_content_type_category_enabled',
	)
);

// Featured Posts Sub Heading.
$wp_customize->add_setting(
	'hot_news_editor_pick_sub_heading',
	array(
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	new Hot_News_Sub_Section_Heading_Custom_Control(
		$wp_customize,
		'hot_news_editor_pick_sub_heading',
		array(
			'label'           => esc_html__( 'Editor Pick Section', 'hot-news' ),
			'settings'        => 'hot_news_editor_pick_sub_heading',
			'section'         => 'hot_news_banner_section',
			'active_callback' => 'hot_news_if_banner_enabled',
		)
	)
);

// Editor Pick title settings.
$wp_customize->add_setting(
	'hot_news_editor_pick_title',
	array(
		'default'           => __( 'Editor Pick', 'hot-news' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'hot_news_editor_pick_title',
	array(
		'label'           => esc_html__( 'Title', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'active_callback' => 'hot_news_if_banner_enabled',
	)
);

// banner featured posts content type settings.
$wp_customize->add_setting(
	'hot_news_editor_pick_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'hot_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'hot_news_editor_pick_content_type',
	array(
		'label'           => esc_html__( 'Editor Pick Content type:', 'hot-news' ),
		'description'     => esc_html__( 'Choose where you want to render the content from.', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'settings'        => 'hot_news_editor_pick_content_type',
		'type'            => 'select',
		'active_callback' => 'hot_news_if_banner_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'hot-news' ),
			'page'     => esc_html__( 'Page', 'hot-news' ),
			'category' => esc_html__( 'Category', 'hot-news' ),
			'recent'   => esc_html__( 'Recent', 'hot-news' ),
		),
	)
);

for ( $i = 1; $i <= 5; $i++ ) {
	// Featured Posts post setting.
	$wp_customize->add_setting(
		'hot_news_editor_pick_post_' . $i,
		array(
			'sanitize_callback' => 'hot_news_sanitize_dropdown_pages',
		)
	);

	$wp_customize->add_control(
		'hot_news_editor_pick_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Post %d', 'hot-news' ), $i ),
			'section'         => 'hot_news_banner_section',
			'type'            => 'select',
			'choices'         => hot_news_get_post_choices(),
			'active_callback' => 'hot_news_editor_pick_section_content_type_post_enabled',
		)
	);

}

// Featured Posts category setting.
$wp_customize->add_setting(
	'hot_news_editor_pick_category',
	array(
		'sanitize_callback' => 'hot_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'hot_news_editor_pick_category',
	array(
		'label'           => esc_html__( 'Category', 'hot-news' ),
		'section'         => 'hot_news_banner_section',
		'type'            => 'select',
		'choices'         => hot_news_get_post_cat_choices(),
		'active_callback' => 'hot_news_editor_pick_section_content_type_category_enabled',
	)
);

/*========================Active Callback==============================*/
function hot_news_if_banner_enabled( $control ) {
	return $control->manager->get_setting( 'hot_news_banner_section_enable' )->value();
}

// Banner News
function hot_news_banner_news_content_type_post_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'hot_news_banner_news_content_type' )->value();
	return hot_news_if_banner_enabled( $control ) && ( 'post' === $content_type );
}
function hot_news_banner_news_content_type_category_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'hot_news_banner_news_content_type' )->value();
	return hot_news_if_banner_enabled( $control ) && ( 'category' === $content_type );
}

// Banner Featured Posts
function hot_news_featured_posts_section_content_type_post_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'hot_news_featured_posts_content_type' )->value();
	return hot_news_if_banner_enabled( $control ) && ( 'post' === $content_type );
}
function hot_news_featured_posts_section_content_type_category_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'hot_news_featured_posts_content_type' )->value();
	return hot_news_if_banner_enabled( $control ) && ( 'category' === $content_type );
}

// Banner Editor Pick
function hot_news_editor_pick_section_content_type_post_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'hot_news_editor_pick_content_type' )->value();
	return hot_news_if_banner_enabled( $control ) && ( 'post' === $content_type );
}
function hot_news_editor_pick_section_content_type_category_enabled( $control ) {
	$content_type = $control->manager->get_setting( 'hot_news_editor_pick_content_type' )->value();
	return hot_news_if_banner_enabled( $control ) && ( 'category' === $content_type );
}
