<?php
/**
 * Moral Theme Customizer
 *
 * @package Moral
 *
 * featured_news section
 */

$wp_customize->add_section(
	'moral_magazine_featured_news',
	array(
		'title' => esc_html__( 'Featured News', 'moral-magazine' ),
		'panel' => 'moral_magazine_home_panel',
	)
);

// featured_news enable settings
$wp_customize->add_setting(
	'moral_magazine_featured_news',
	array(
		'sanitize_callback' => 'moral_magazine_sanitize_select',
		'default' => 'disable'
	)
);

$wp_customize->add_control(
	'moral_magazine_featured_news',
	array(
		'section'		=> 'moral_magazine_featured_news',
		'label'			=> esc_html__( 'Content type:', 'moral-magazine' ),
		'description'			=> esc_html__( 'Choose where you want to render the content from.', 'moral-magazine' ),
		'type'			=> 'select',
		'choices'		=> array( 
				'disable' => esc_html__( '--Disable--', 'moral-magazine' ),
				'post' => esc_html__( 'Post', 'moral-magazine' ),
		 	)
	)
);


$wp_customize->add_setting(
	'moral_magazine_featured_news_title',
	array(
		'sanitize_callback' => 'sanitize_text_field',
		'default' => esc_html__( 'Featured News', 'moral-magazine' ),
		'transport'	=> 'postMessage',
	)
);

$wp_customize->add_control(
	'moral_magazine_featured_news_title',
	array(
		'section'		=> 'moral_magazine_featured_news',
		'label'			=> esc_html__( 'Title:', 'moral-magazine' ),
	)
);

$wp_customize->selective_refresh->add_partial( 
	'moral_magazine_featured_news_title', 
	array(
        'selector'            => '#featured_news-posts .section-subtitle',
		'render_callback'     => 'moral_magazine_featured_news_partial_title',
	) 
);


$featured_news_num = 4;
for ($i=1; $i <= $featured_news_num ; $i++) { 
	// featured_news post setting
	$wp_customize->add_setting(
		'moral_magazine_featured_news_post_'.$i,
		array(
			'sanitize_callback' => 'moral_magazine_sanitize_dropdown_pages',
		)
	);

	$wp_customize->add_control(
		'moral_magazine_featured_news_post_'.$i,
		array(
			'section'		=> 'moral_magazine_featured_news',
			'label'			=> esc_html__( 'Post ', 'moral-magazine' ).$i,
			'type'			=> 'select',
			'choices'		=> moral_magazine_get_post_choices(),
		)
	);

}

