<?php
/**
 * Tile Posts Section
 *
 * @package Majestic Blog
 */

$wp_customize->add_section(
	'majestic_blog_tile_posts_section',
	array(
		'panel' => 'majestic_blog_front_page_options',
		'title' => esc_html__( 'Tile Posts Section', 'majestic-blog' ),
	)
);

// Tile Posts Section - Enable Section.
$wp_customize->add_setting(
	'majestic_blog_enable_tile_posts_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'majestic_blog_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Majestic_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'majestic_blog_enable_tile_posts_section',
		array(
			'label'    => esc_html__( 'Enable Tile Posts Section', 'majestic-blog' ),
			'section'  => 'majestic_blog_tile_posts_section',
			'settings' => 'majestic_blog_enable_tile_posts_section',
		)
	)
);

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

// Tile Posts Section - Section Title.
$wp_customize->add_setting(
	'majestic_blog_tile_posts_section_title',
	array(
		'default'           => __( 'Tile Posts Section', 'majestic-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'majestic_blog_tile_posts_section_title',
	array(
		'label'           => esc_html__( 'Section Title', 'majestic-blog' ),
		'section'         => 'majestic_blog_tile_posts_section',
		'settings'        => 'majestic_blog_tile_posts_section_title',
		'type'            => 'text',
		'active_callback' => 'majestic_blog_is_tile_posts_section_enabled',
	)
);

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

$wp_customize->add_control(
	'majestic_blog_tile_posts_subtitle',
	array(
		'label'           => esc_html__( 'Section Subtitle', 'majestic-blog' ),
		'section'         => 'majestic_blog_tile_posts_section',
		'settings'        => 'majestic_blog_tile_posts_subtitle',
		'type'            => 'text',
		'active_callback' => 'majestic_blog_is_tile_posts_section_enabled',
	)
);

// Tile Posts Section - Content Type.
$wp_customize->add_setting(
	'majestic_blog_tile_posts_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'majestic_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'majestic_blog_tile_posts_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'majestic-blog' ),
		'section'         => 'majestic_blog_tile_posts_section',
		'settings'        => 'majestic_blog_tile_posts_content_type',
		'type'            => 'select',
		'active_callback' => 'majestic_blog_is_tile_posts_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'majestic-blog' ),
			'category' => esc_html__( 'Category', 'majestic-blog' ),
		),
	)
);

// Tile Posts Section - Select Tile Posts Category.
$wp_customize->add_setting(
	'majestic_blog_tile_posts_content_category',
	array(
		'sanitize_callback' => 'majestic_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'majestic_blog_tile_posts_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'majestic-blog' ),
		'section'         => 'majestic_blog_tile_posts_section',
		'settings'        => 'majestic_blog_tile_posts_content_category',
		'active_callback' => 'majestic_blog_is_tile_posts_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => majestic_blog_get_post_cat_choices(),
	)
);

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

	$wp_customize->add_control(
		'majestic_blog_tile_posts_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'majestic-blog' ), $i ),
			'section'         => 'majestic_blog_tile_posts_section',
			'settings'        => 'majestic_blog_tile_posts_content_post_' . $i,
			'active_callback' => 'majestic_blog_is_tile_posts_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => majestic_blog_get_post_choices(),
		)
	);

}
