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

$default = magazine_bell_get_default_theme_options();

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

$wp_customize->add_setting( 'theme_options[disable_recent_section]',
	array(
		'default'           => $default['disable_recent_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_recent_section]',
    array(
		'label' 			=> __('Enable/Disable Recent Posts Section', 'magazine-bell'),
		'section'    		=> 'section_home_recent',
		 'settings'  		=> 'theme_options[disable_recent_section]',
		'on_off_label' 		=> magazine_bell_switch_options(),
    )
) );

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

$wp_customize->add_control( 'theme_options[recent_content_align]', array(
	'label'             => esc_html__( 'Choose Content Align', 'magazine-bell' ),
	'section'           => 'section_home_recent',
	'type'              => 'radio',
	'active_callback' => 'magazine_bell_recent_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' )
		)
) );


//Blog & News Section title
$wp_customize->add_setting('theme_options[recent_title]', 
	array(
	'default'           => $default['recent_title'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'sanitize_text_field'
	)
);

$wp_customize->add_control('theme_options[recent_title]', 
	array(
	'label'       => __('Section Title', 'magazine-bell'),
	'section'     => 'section_home_recent',   
	'settings'    => 'theme_options[recent_title]',
	'active_callback' => 'magazine_bell_recent_active',		
	'type'        => 'text'
	)
);

// Number of items
$wp_customize->add_setting('theme_options[number_of_recent_column]', 
	array(
	'default' 			=> $default['number_of_recent_column'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'magazine_bell_sanitize_number_range'
	)
);

$wp_customize->add_control('theme_options[number_of_recent_column]', 
	array(
	'label'       => __('Number Of Recent Column', 'magazine-bell'),
	'description' => __('Save & Refresh the customizer to see its effect. Maximum is 3.', 'magazine-bell'),
	'section'     => 'section_home_recent',   
	'settings'    => 'theme_options[number_of_recent_column]',		
	'type'        => 'number',
	'active_callback' => 'magazine_bell_recent_active',
	'input_attrs' => array(
			'min'	=> 1,
			'max'	=> 3,
			'step'	=> 1,
		),
	)
);

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

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

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

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

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

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

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


$number_of_recent_items = magazine_bell_get_option( 'number_of_recent_items' );

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

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

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

//Advertisment Section

// Advertisment hr setting and control
$wp_customize->add_setting( 'theme_options[recent_ads_hr]', array(
	'sanitize_callback' => 'sanitize_text_field'
) );

$wp_customize->add_control( new Magazine_Bell_Customize_Horizontal_Line( $wp_customize, 'theme_options[recent_ads_hr]',
	array(
		'section'         => 'section_home_recent',
		'active_callback' => 'magazine_bell_recent_active',
		'type'			  => 'hr',
) ) );
$wp_customize->add_setting( 'theme_options[disable_recent_ads_section]',
	array(
		'default'           => $default['disable_recent_ads_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_recent_ads_section]',
    array(
		'label' 			=> __('Enable/Disable Category News Ads', 'magazine-bell'),
		'section'    		=> 'section_home_recent',
		'settings'  		=> 'theme_options[disable_recent_ads_section]',
		'active_callback' => 'magazine_bell_recent_active',
		'on_off_label' 		=> magazine_bell_switch_options(),
    )
) );

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

$wp_customize->add_control( 'theme_options[recent_column_option]', array(
	'label'             => esc_html__( 'Choose ADS Column', 'magazine-bell' ),
	'section'           => 'section_home_recent',
	'type'              => 'radio',
	'active_callback' => 'magazine_bell_recent_active',
	'choices'				=> array( 
		'col-1'     => esc_html__( 'Column One', 'magazine-bell' ), 
		'col-2'     => esc_html__( 'Column Two', 'magazine-bell' ),
		)
) );

// Number of items
$wp_customize->add_setting('theme_options[number_of_recent_ads]', 
	array(
	'default' 			=> $default['number_of_recent_ads'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'magazine_bell_sanitize_number_range'
	)
);

$wp_customize->add_control('theme_options[number_of_recent_ads]', 
	array(
	'label'       => __('Number of Items', 'magazine-bell'),
	'description' => __('Save & Refresh the customizer to see its effect. Maximum is 2.', 'magazine-bell'),
	'section'     => 'section_home_recent',   
	'settings'    => 'theme_options[number_of_recent_ads]',		
	'type'        => 'number',
	'active_callback' => 'magazine_bell_recent_active',
	'input_attrs' => array(
			'min'	=> 1,
			'max'	=> 2,
			'step'	=> 1,
		),
	)
);
$number_of_recent_ads = magazine_bell_get_option( 'number_of_recent_ads' );

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

// recent title setting and control
	$wp_customize->add_setting( 'theme_options[recent_ads_img_' . $i . ']', array(
		'type'              => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
	) );

	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'theme_options[recent_ads_img_' . $i . ']', array(
		'label'       =>sprintf( esc_html__( 'Select ADS Image %d', 'magazine-bell' ), $i ),
		'section'        	=> 'section_home_recent',
		'settings'    		=> 'theme_options[recent_ads_img_'.$i.']',	
		'active_callback' 	=> 'magazine_bell_recent_active',
	) ) );

	// recent title setting and control
	$wp_customize->add_setting( 'theme_options[recent_ads_url_' . $i . ']', array(
		'type'              => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
	) );

	$wp_customize->add_control( 'theme_options[recent_ads_url_' . $i . ']', array(
		'label'           	=> sprintf( __( 'ADS Url %d', 'magazine-bell' ), $i ),
		'section'        	=> 'section_home_recent',
		'settings'    		=> 'theme_options[recent_ads_url_'.$i.']',	
		'active_callback' 	=> 'magazine_bell_recent_active',
		'type'				=> 'url',
	) );
}