<?php
/**
 * List Posts Section
 *
 * @package Zenith Blog
 */

$wp_customize->add_section(
	'zenith_blog_list_posts_section',
	array(
		'panel' => 'zenith_blog_front_page_options',
		'title' => esc_html__( 'List Posts Section', 'zenith-blog' ),
	)
);

// List Posts Section - Enable Section.
$wp_customize->add_setting(
	'zenith_blog_enable_list_posts_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_list_posts_section',
		array(
			'label'    => esc_html__( 'Enable List Posts Section', 'zenith-blog' ),
			'section'  => 'zenith_blog_list_posts_section',
			'settings' => 'zenith_blog_enable_list_posts_section',
			'priority' => 10,
		)
	)
);

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

// List Posts Section - Section Title.
$wp_customize->add_setting(
	'zenith_blog_list_posts_title',
	array(
		'default'           => __( 'List Posts', 'zenith-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'zenith_blog_list_posts_title',
	array(
		'label'           => esc_html__( 'Section Title', 'zenith-blog' ),
		'section'         => 'zenith_blog_list_posts_section',
		'settings'        => 'zenith_blog_list_posts_title',
		'type'            => 'text',
		'active_callback' => 'zenith_blog_is_list_posts_section_enabled',
		'priority'        => 20,
	)
);

// List Posts Section - Section Subtitle.
$wp_customize->add_setting(
	'zenith_blog_list_posts_subtitle',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'zenith_blog_list_posts_subtitle',
	array(
		'label'           => esc_html__( 'Section Subtitle', 'zenith-blog' ),
		'section'         => 'zenith_blog_list_posts_section',
		'settings'        => 'zenith_blog_list_posts_subtitle',
		'type'            => 'text',
		'active_callback' => 'zenith_blog_is_list_posts_section_enabled',
		'priority'        => 30,
	)
);

// List Posts Section - Content Type.
$wp_customize->add_setting(
	'zenith_blog_list_posts_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'zenith_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'zenith_blog_list_posts_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'zenith-blog' ),
		'section'         => 'zenith_blog_list_posts_section',
		'settings'        => 'zenith_blog_list_posts_content_type',
		'type'            => 'select',
		'active_callback' => 'zenith_blog_is_list_posts_section_enabled',
		'priority'        => 40,
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'zenith-blog' ),
			'category' => esc_html__( 'Category', 'zenith-blog' ),
		),
	)
);

for ( $i = 1; $i <= 6; $i++ ) {
	// List Posts Section - Select Post.
	$wp_customize->add_setting(
		'zenith_blog_list_posts_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'zenith_blog_list_posts_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'zenith-blog' ), $i ),
			'section'         => 'zenith_blog_list_posts_section',
			'settings'        => 'zenith_blog_list_posts_content_post_' . $i,
			'active_callback' => 'zenith_blog_is_list_posts_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => zenith_blog_get_post_choices(),
			'priority'        => 50,
		)
	);

}

// List Posts Section - Select Category.
$wp_customize->add_setting(
	'zenith_blog_list_posts_content_category',
	array(
		'sanitize_callback' => 'zenith_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'zenith_blog_list_posts_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'zenith-blog' ),
		'section'         => 'zenith_blog_list_posts_section',
		'settings'        => 'zenith_blog_list_posts_content_category',
		'active_callback' => 'zenith_blog_is_list_posts_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => zenith_blog_get_post_cat_choices(),
		'priority'        => 60,
	)
);
