<?php
/**
 * Posts Carousel Section
 *
 * @package Headline News
 */

$wp_customize->add_section(
	'headline_news_posts_carousel_section',
	array(
		'panel' => 'headline_news_front_page_options',
		'title' => esc_html__( 'Posts Carousel Section', 'headline-news' ),
	)
);

// Posts Carousel Section - Enable Section.
$wp_customize->add_setting(
	'headline_news_enable_posts_carousel_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'headline_news_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Headline_News_Toggle_Switch_Custom_Control(
		$wp_customize,
		'headline_news_enable_posts_carousel_section',
		array(
			'label'    => esc_html__( 'Enable Posts Carousel Section', 'headline-news' ),
			'section'  => 'headline_news_posts_carousel_section',
			'settings' => 'headline_news_enable_posts_carousel_section',
		)
	)
);

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

// Latest Posts Section - Section Title.
$wp_customize->add_setting(
	'headline_news_posts_carousel_title',
	array(
		'default'           => __( 'Posts Carousel', 'headline-news' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'headline_news_posts_carousel_title',
	array(
		'label'           => esc_html__( 'Section Title', 'headline-news' ),
		'section'         => 'headline_news_posts_carousel_section',
		'settings'        => 'headline_news_posts_carousel_title',
		'type'            => 'text',
		'active_callback' => 'headline_news_is_posts_carousel_section_enabled',
	)
);

// Posts Carousel Section - Posts Carousel Content Type.
$wp_customize->add_setting(
	'headline_news_posts_carousel_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'headline_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'headline_news_posts_carousel_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'headline-news' ),
		'section'         => 'headline_news_posts_carousel_section',
		'settings'        => 'headline_news_posts_carousel_content_type',
		'type'            => 'select',
		'active_callback' => 'headline_news_is_posts_carousel_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'headline-news' ),
			'category' => esc_html__( 'Category', 'headline-news' ),
		),
	)
);

// Posts Carousel Section - Select Post Carousel Category.
$wp_customize->add_setting(
	'headline_news_posts_carousel_content_category',
	array(
		'sanitize_callback' => 'headline_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'headline_news_posts_carousel_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'headline-news' ),
		'section'         => 'headline_news_posts_carousel_section',
		'settings'        => 'headline_news_posts_carousel_content_category',
		'active_callback' => 'headline_news_is_posts_carousel_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => headline_news_get_post_cat_choices(),
	)
);

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

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

	$wp_customize->add_control(
		'headline_news_posts_carousel_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'headline-news' ), $i ),
			'section'         => 'headline_news_posts_carousel_section',
			'settings'        => 'headline_news_posts_carousel_content_post_' . $i,
			'active_callback' => 'headline_news_is_posts_carousel_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => headline_news_get_post_choices(),
		)
	);

}
