<?php
/**
 * Flash Articles Section
 *
 * @package Rhythm Blog
 */

$wp_customize->add_section(
	'rhythm_blog_flash_articles_section',
	array(
		'panel' => 'rhythm_blog_front_page_options',
		'title' => esc_html__( 'Flash Articles Section', 'rhythm-blog' ),
	)
);

// Flash Articles Section - Enable Section.
$wp_customize->add_setting(
	'rhythm_blog_enable_flash_articles_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'rhythm_blog_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Rhythm_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'rhythm_blog_enable_flash_articles_section',
		array(
			'label'    => esc_html__( 'Enable Flash Articles Section', 'rhythm-blog' ),
			'section'  => 'rhythm_blog_flash_articles_section',
			'settings' => 'rhythm_blog_enable_flash_articles_section',
		)
	)
);

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

// Flash Articles Section - Section Title.
$wp_customize->add_setting(
	'rhythm_blog_flash_articles_title',
	array(
		'default'           => __( 'Flash Articles', 'rhythm-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'rhythm_blog_flash_articles_title',
	array(
		'label'           => esc_html__( 'Section Title', 'rhythm-blog' ),
		'section'         => 'rhythm_blog_flash_articles_section',
		'settings'        => 'rhythm_blog_flash_articles_title',
		'type'            => 'text',
		'active_callback' => 'rhythm_blog_is_flash_articles_section_enabled',
	)
);

// Flash Articles Section - Content Type.
$wp_customize->add_setting(
	'rhythm_blog_flash_articles_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'rhythm_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'rhythm_blog_flash_articles_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'rhythm-blog' ),
		'section'         => 'rhythm_blog_flash_articles_section',
		'settings'        => 'rhythm_blog_flash_articles_content_type',
		'type'            => 'select',
		'active_callback' => 'rhythm_blog_is_flash_articles_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'rhythm-blog' ),
			'category' => esc_html__( 'Category', 'rhythm-blog' ),
		),
	)
);

for ( $i = 1; $i <= 5; $i++ ) {
	// Flash Articles Section - Select Post.
	$wp_customize->add_setting(
		'rhythm_blog_flash_articles_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'rhythm_blog_flash_articles_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'rhythm-blog' ), $i ),
			'section'         => 'rhythm_blog_flash_articles_section',
			'settings'        => 'rhythm_blog_flash_articles_content_post_' . $i,
			'active_callback' => 'rhythm_blog_is_flash_articles_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => rhythm_blog_get_post_choices(),
		)
	);

}

// Flash Articles Section - Select Category.
$wp_customize->add_setting(
	'rhythm_blog_flash_articles_content_category',
	array(
		'sanitize_callback' => 'rhythm_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'rhythm_blog_flash_articles_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'rhythm-blog' ),
		'section'         => 'rhythm_blog_flash_articles_section',
		'settings'        => 'rhythm_blog_flash_articles_content_category',
		'active_callback' => 'rhythm_blog_is_flash_articles_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => rhythm_blog_get_post_cat_choices(),
	)
);
