<?php
/**
 * Tile Grid Posts Section
 *
 * @package Cosmic Blog
 */

$wp_customize->add_section(
	'cosmic_blog_tile_grid_section',
	array(
		'panel'    => 'cosmic_blog_front_page_options',
		'title'    => esc_html__( 'Tile Grid Posts Section', 'cosmic-blog' ),
		'priority' => 20,
	)
);

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

$wp_customize->add_control(
	new Cosmic_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'cosmic_blog_enable_tile_grid_section',
		array(
			'label'    => esc_html__( 'Enable Tile Grid Posts Section', 'cosmic-blog' ),
			'section'  => 'cosmic_blog_tile_grid_section',
			'settings' => 'cosmic_blog_enable_tile_grid_section',
		)
	)
);

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

// Tile Grid Posts Section - Section Title.
$wp_customize->add_setting(
	'cosmic_blog_tile_grid_section_title',
	array(
		'default'           => __( 'Explore Asia Architecture', 'cosmic-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'cosmic_blog_tile_grid_section_title',
	array(
		'label'           => esc_html__( 'Section Title', 'cosmic-blog' ),
		'section'         => 'cosmic_blog_tile_grid_section',
		'settings'        => 'cosmic_blog_tile_grid_section_title',
		'type'            => 'text',
		'active_callback' => 'cosmic_blog_is_tile_grid_section_enabled',
	)
);

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

$wp_customize->add_control(
	'cosmic_blog_tile_grid_section_subtitle',
	array(
		'label'           => esc_html__( 'Section Subtitle', 'cosmic-blog' ),
		'section'         => 'cosmic_blog_tile_grid_section',
		'settings'        => 'cosmic_blog_tile_grid_section_subtitle',
		'type'            => 'text',
		'active_callback' => 'cosmic_blog_is_tile_grid_section_enabled',
	)
);

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

$wp_customize->add_control(
	'cosmic_blog_tile_grid_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'cosmic-blog' ),
		'section'         => 'cosmic_blog_tile_grid_section',
		'settings'        => 'cosmic_blog_tile_grid_content_type',
		'type'            => 'select',
		'active_callback' => 'cosmic_blog_is_tile_grid_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'cosmic-blog' ),
			'category' => esc_html__( 'Category', 'cosmic-blog' ),
		),
	)
);

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

$wp_customize->add_control(
	'cosmic_blog_tile_grid_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'cosmic-blog' ),
		'section'         => 'cosmic_blog_tile_grid_section',
		'settings'        => 'cosmic_blog_tile_grid_content_category',
		'active_callback' => 'cosmic_blog_is_tile_grid_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => cosmic_blog_get_post_cat_choices(),
	)
);

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

	$wp_customize->add_control(
		'cosmic_blog_tile_grid_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'cosmic-blog' ), $i ),
			'section'         => 'cosmic_blog_tile_grid_section',
			'settings'        => 'cosmic_blog_tile_grid_content_post_' . $i,
			'active_callback' => 'cosmic_blog_is_tile_grid_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => cosmic_blog_get_post_choices(),
		)
	);

}
