<?php
/**
 * Grid Post options.
 *
 * @package Magazine Bell
 */

$default = magazine_bell_get_default_theme_options();

// Blog & News Section
$wp_customize->add_section( 'section_home_trending',
	array(
		'title'      => __( 'Grid News Section', 'magazine-bell' ),
		'capability' => 'edit_theme_options',
		'panel'      => 'home_page_panel',
		)
);

$wp_customize->add_setting( 'theme_options[disable_trending_section]',
	array(
		'default'           => $default['disable_trending_section'],
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'magazine_bell_sanitize_switch_control',
	)
);
$wp_customize->add_control( new Magazine_Bell_Switch_Control( $wp_customize, 'theme_options[disable_trending_section]',
    array(
		'label' 			=> __('Enable/Disable Grid News Section', 'magazine-bell'),
		'section'    		=> 'section_home_trending',
		 'settings'  		=> 'theme_options[disable_trending_section]',
		'on_off_label' 		=> magazine_bell_switch_options(),
    )
) );

// Add arrow enable setting and control.
$wp_customize->add_setting( 'theme_options[trending_content_align]', array(
	'default'           => $default['trending_content_align'],
	'sanitize_callback' => 'magazine_bell_sanitize_select',
) );

$wp_customize->add_control( 'theme_options[trending_content_align]', array(
	'label'             => esc_html__( 'Choose Content Align', 'magazine-bell' ),
	'section'           => 'section_home_trending',
	'type'              => 'radio',
	'active_callback' => 'magazine_bell_trending_active',
	'choices'				=> array( 
		'content-right'     => esc_html__( 'Right Side', 'magazine-bell' ), 
		'content-center'     => esc_html__( 'Center Side', 'magazine-bell' ), 
		'content-left'     => esc_html__( 'Left Side', 'magazine-bell' ), 
		'content-justify'     => esc_html__( 'Justify', 'magazine-bell' )
		)
) );

// Add category enable setting and control.
$wp_customize->add_setting( 'theme_options[trending_category_enable]', array(
	'default'           => $default['trending_category_enable'],
	'sanitize_callback' => 'magazine_bell_sanitize_checkbox',
) );

$wp_customize->add_control( 'theme_options[trending_category_enable]', array(
	'label'             => esc_html__( 'Enable Category', 'magazine-bell' ),
	'section'           => 'section_home_trending',
	'type'              => 'checkbox',
	'active_callback' => 'magazine_bell_trending_active',
) );	
// Add content enable setting and control.
$wp_customize->add_setting( 'theme_options[trending_content_enable]', array(
	'default'           => $default['trending_content_enable'],
	'sanitize_callback' => 'magazine_bell_sanitize_checkbox',
) );

$wp_customize->add_control( 'theme_options[trending_content_enable]', array(
	'label'             => esc_html__( 'Enable Content', 'magazine-bell' ),
	'section'           => 'section_home_trending',
	'type'              => 'checkbox',
	'active_callback' => 'magazine_bell_trending_active',
) );

// Add posted on enable setting and control.
$wp_customize->add_setting( 'theme_options[trending_posted_on_enable]', array(
	'default'           => $default['trending_posted_on_enable'],
	'sanitize_callback' => 'magazine_bell_sanitize_checkbox',
) );

$wp_customize->add_control( 'theme_options[trending_posted_on_enable]', array(
	'label'             => esc_html__( 'Enable Date', 'magazine-bell' ),
	'section'           => 'section_home_trending',
	'type'              => 'checkbox',
	'active_callback' => 'magazine_bell_trending_active',
) );

// Add posted on enable setting and control.
$wp_customize->add_setting( 'theme_options[trending_author_enable]', array(
	'default'           => $default['trending_author_enable'],
	'sanitize_callback' => 'magazine_bell_sanitize_checkbox',
) );

$wp_customize->add_control( 'theme_options[trending_author_enable]', array(
	'label'             => esc_html__( 'Enable Author', 'magazine-bell' ),
	'section'           => 'section_home_trending',
	'type'              => 'checkbox',
	'active_callback' => 'magazine_bell_trending_active',
) );

$number_of_trending_items = magazine_bell_get_option( 'number_of_trending_items' );

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

	// News
	$wp_customize->add_setting('theme_options[trending_post_'.$i.']', 
		array(
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',	
		'sanitize_callback' => 'magazine_bell_dropdown_pages'
		)
	);

	$wp_customize->add_control('theme_options[trending_post_'.$i.']', 
		array(
		'label'       => sprintf( __('Select Post #%1$s', 'magazine-bell'), $i),
		'section'     => 'section_home_trending',   
		'settings'    => 'theme_options[trending_post_'.$i.']',		
		'type'        => 'select',
		'choices'	  => magazine_bell_post_choices(),
		'active_callback' => 'magazine_bell_trending_active',
		)
	);
}