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

$default = magazine_bell_get_default_theme_options();

// Must Read Post Section
$wp_customize->add_section( 'section_home_mustread',
	array(
		'title'      => __( 'Must Read News', 'magazine-bell' ),
		'capability' => 'edit_theme_options',
		'panel'      => 'home_page_panel',
		'active_callback' => 'magazine_bell_mustread_design_enable',
		)
);

$wp_customize->add_setting( 'theme_options[disable_mustread_section]',
	array(
		'default'           => $default['disable_mustread_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_mustread_section]',
    array(
		'label' 			=> __('Enable/Disable Must Read Post Section', 'magazine-bell'),
		'section'    		=> 'section_home_mustread',
		 'settings'  		=> 'theme_options[disable_mustread_section]',
		'on_off_label' 		=> magazine_bell_switch_options(),
    )
) );


$wp_customize->add_setting( 'theme_options[mustread_background_color]', array(
    'sanitize_callback' => 'sanitize_hex_color', // The hue is stored as a positive integer.
    'default' 			=> $default['mustread_background_color'],
    
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'theme_options[mustread_background_color]', array(
    'label'    => esc_html__( 'Background Color', 'magazine-bell' ),
    'section'  => 'section_home_mustread',
    'active_callback' => 'magazine_bell_mustread_active',
) ) );

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

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

//Must Read Post Section title
$wp_customize->add_setting('theme_options[mustread_title]', 
	array(
	'default'           => $default['mustread_title'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'sanitize_text_field'
	)
);

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

$number_of_mustread_items = magazine_bell_get_option( 'number_of_mustread_items' );

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

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

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

//==============Advertisment Section===========//

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

$wp_customize->add_control( new Magazine_Bell_Customize_Horizontal_Line( $wp_customize, 'theme_options[mustread_ads_hr]',
	array(
		'section'         => 'section_home_mustread',
		'active_callback' => 'magazine_bell_mustread_active',
		'type'			  => 'hr',
) ) );
$wp_customize->add_setting( 'theme_options[disable_mustread_ads_section]',
	array(
		'default'           => $default['disable_mustread_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_mustread_ads_section]',
    array(
		'label' 			=> __('Enable/Disable News Ads', 'magazine-bell'),
		'section'    		=> 'section_home_mustread',
		'settings'  		=> 'theme_options[disable_mustread_ads_section]',
		'active_callback' => 'magazine_bell_mustread_active',
		'on_off_label' 		=> magazine_bell_switch_options(),
    )
) );

$number_of_mustread_ads = magazine_bell_get_option( 'number_of_mustread_ads' );

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

// mustread title setting and control
	$wp_customize->add_setting( 'theme_options[mustread_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[mustread_ads_img_' . $i . ']', array(
		'label'       =>sprintf( esc_html__( 'Select ADS Image %d', 'magazine-bell' ), $i ),
		'section'        	=> 'section_home_mustread',
		'settings'    		=> 'theme_options[mustread_ads_img_'.$i.']',	
		'active_callback' 	=> 'magazine_bell_mustread_active',
	) ) );

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

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