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

$default = magazine_bell_get_default_theme_options();

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

$wp_customize->add_setting( 'theme_options[disable_popular_section]',
	array(
		'default'           => $default['disable_popular_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_popular_section]',
    array(
		'label' 			=> __('Enable/Disable Popular News Section', 'magazine-bell'),
		'section'    		=> 'section_home_popular',
		 'settings'  		=> 'theme_options[disable_popular_section]',
		'on_off_label' 		=> magazine_bell_switch_options(),
    )
) );

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

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

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

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

$wp_customize->add_control( 'theme_options[popular_content_align]', array(
	'label'             => esc_html__( 'Choose Content Align', 'magazine-bell' ),
	'section'           => 'section_home_popular',
	'type'              => 'radio',
	'active_callback' => 'magazine_bell_popular_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[popular_category_enable]', array(
	'default'           => $default['popular_category_enable'],
	'sanitize_callback' => 'magazine_bell_sanitize_checkbox',
) );

$wp_customize->add_control( 'theme_options[popular_category_enable]', array(
	'label'             => esc_html__( 'Enable Category', 'magazine-bell' ),
	'section'           => 'section_home_popular',
	'type'              => 'checkbox',
	'active_callback' => 'magazine_bell_popular_active',
) );	

// Setting  Team Category.
$wp_customize->add_setting( 'theme_options[popular_category]',
	array(

	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'absint',
	)
);
$wp_customize->add_control(
	new Magazine_Bell_Dropdown_Taxonomies_Control( $wp_customize, 'theme_options[popular_category]',
		array(
		'label'    => __( 'Select Category', 'magazine-bell' ),
		'section'  => 'section_home_popular',
		'settings' => 'theme_options[popular_category]',	
		'active_callback' => 'magazine_bell_popular_active',		
		)
	)
);

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

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

$wp_customize->add_control( new Magazine_Bell_Customize_Horizontal_Line( $wp_customize, 'theme_options[popular_ads_hr]',
	array(
		'section'         => 'section_home_popular',
		'active_callback' => 'magazine_bell_popular_active',
		'type'			  => 'hr',
) ) );
$wp_customize->add_setting( 'theme_options[disable_popular_ads_section]',
	array(
		'default'           => $default['disable_popular_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_popular_ads_section]',
    array(
		'label' 			=> __('Enable/Disable Category News Ads', 'magazine-bell'),
		'section'    		=> 'section_home_popular',
		'settings'  		=> 'theme_options[disable_popular_ads_section]',
		'active_callback' => 'magazine_bell_popular_active',
		'on_off_label' 		=> magazine_bell_switch_options(),
    )
) );

$number_of_popular_ads = magazine_bell_get_option( 'number_of_popular_ads' );

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

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

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

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