<?php
/**
 * Tile and Grid Section
 *
 * @package Millennium News
 */

$wp_customize->add_section(
	'millennium_news_tile_grid_section',
	array(
		'panel' => 'millennium_news_front_page_options',
		'title' => esc_html__( 'Tile and Grid Section', 'millennium-news' ),
	)
);

// Tile and Grid Section - Enable Section.
$wp_customize->add_setting(
	'millennium_news_enable_tile_grid_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'millennium_news_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Millennium_News_Toggle_Switch_Custom_Control(
		$wp_customize,
		'millennium_news_enable_tile_grid_section',
		array(
			'label'    => esc_html__( 'Enable Tile and Grid Section', 'millennium-news' ),
			'section'  => 'millennium_news_tile_grid_section',
			'settings' => 'millennium_news_enable_tile_grid_section',
		)
	)
);

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

// Latest Posts Section - Section Title.
$wp_customize->add_setting(
	'millennium_news_tile_grid_title',
	array(
		'default'           => __( 'Tile and Grid', 'millennium-news' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'millennium_news_tile_grid_title',
	array(
		'label'           => esc_html__( 'Section Title', 'millennium-news' ),
		'section'         => 'millennium_news_tile_grid_section',
		'settings'        => 'millennium_news_tile_grid_title',
		'type'            => 'text',
		'active_callback' => 'millennium_news_is_tile_grid_section_enabled',
	)
);

// Tile and Grid Section - Tile and Grid Content Type.
$wp_customize->add_setting(
	'millennium_news_tile_grid_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'millennium_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'millennium_news_tile_grid_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'millennium-news' ),
		'section'         => 'millennium_news_tile_grid_section',
		'settings'        => 'millennium_news_tile_grid_content_type',
		'type'            => 'select',
		'active_callback' => 'millennium_news_is_tile_grid_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'millennium-news' ),
			'category' => esc_html__( 'Category', 'millennium-news' ),
		),
	)
);

// Tile and Grid Section - Select Banner Category.
$wp_customize->add_setting(
	'millennium_news_tile_grid_content_category',
	array(
		'sanitize_callback' => 'millennium_news_sanitize_select',
	)
);

$wp_customize->add_control(
	'millennium_news_tile_grid_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'millennium-news' ),
		'section'         => 'millennium_news_tile_grid_section',
		'settings'        => 'millennium_news_tile_grid_content_category',
		'active_callback' => 'millennium_news_is_tile_grid_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => millennium_news_get_post_cat_choices(),
	)
);

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

	// Tile and Grid Section - Select Banner Post.
	$wp_customize->add_setting(
		'millennium_news_tile_grid_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'millennium_news_tile_grid_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'millennium-news' ), $i ),
			'section'         => 'millennium_news_tile_grid_section',
			'settings'        => 'millennium_news_tile_grid_content_post_' . $i,
			'active_callback' => 'millennium_news_is_tile_grid_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => millennium_news_get_post_choices(),
		)
	);

}

// Post Thumbnail Section - Button Label.
$wp_customize->add_setting(
	'millennium_news_tile_grid_button_label',
	array(
		'default'           => __( 'View All', 'millennium-news' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'millennium_news_tile_grid_button_label',
	array(
		'label'           => esc_html__( 'Button Label', 'millennium-news' ),
		'section'         => 'millennium_news_tile_grid_section',
		'settings'        => 'millennium_news_tile_grid_button_label',
		'type'            => 'text',
		'active_callback' => 'millennium_news_is_tile_grid_section_enabled',
	)
);

// Post Thumbnail Section - Button Link.
$wp_customize->add_setting(
	'millennium_news_tile_grid_button_link',
	array(
		'default'           => '#',
		'sanitize_callback' => 'esc_url_raw',
	)
);

$wp_customize->add_control(
	'millennium_news_tile_grid_button_link',
	array(
		'label'           => esc_html__( 'Button Link', 'millennium-news' ),
		'section'         => 'millennium_news_tile_grid_section',
		'settings'        => 'millennium_news_tile_grid_button_link',
		'type'            => 'url',
		'active_callback' => 'millennium_news_is_tile_grid_section_enabled',
	)
);
