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

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

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

$wp_customize->add_control(
	'moral_magazine_business_news',
	array(
		'section'		=> 'moral_magazine_business_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_business_news_title',
	array(
		'sanitize_callback' => 'sanitize_text_field',
		'default' => esc_html__( 'Business News', 'moral-magazine' ),
		'transport'	=> 'postMessage',
	)
);

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

$wp_customize->selective_refresh->add_partial( 
	'moral_magazine_business_news_title', 
	array(
        'selector'            => '#business_news-posts .section-subtitle',
		'render_callback'     => 'moral_magazine_business_news_partial_title',
	) 
);



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

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

$wp_customize->add_setting( 'moral_magazine_business_news_ads_image', array(
	'sanitize_callback' => 'moral_magazine_sanitize_image',
	'default'			=> get_template_directory_uri() . '/assets/img/site-advertisement.jpg',
) );

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'moral_magazine_business_news_ads_image',
	array(
	'label'       		=> esc_html__( 'Ads Image', 'moral-magazine' ),
	'description' 		=> sprintf( esc_html__( 'Recommended size: %1$dpx x %2$dpx ', 'moral-magazine' ), 810, 120 ),
	'section'     		=> 'moral_magazine_business_news',
) ) );

// ads link setting and control
$wp_customize->add_setting( 'moral_magazine_business_news_ads_image_url', array(
	'sanitize_callback' => 'esc_url_raw',
) );

$wp_customize->add_control( 'moral_magazine_business_news_ads_image_url', array(
	'label'           	=> esc_html__( 'Ads Url', 'moral-magazine' ),
	'section'        	=> 'moral_magazine_business_news',
	'type'				=> 'url',
) );
