<?php
/**
 * Theme Ostrich Customizer
 *
 * @package Ostrich Magazine
 *
 * blog section
 */



$wp_customize->add_section(
	'ostrich_magazine_blog',
	array(
		'title' => esc_html__( 'Blog Section', 'ostrich-magazine' ),
		'panel' => 'ostrich_magazine_home_panel',
	)
);

$wp_customize->add_setting( 'ostrich_magazine_blog_enable',
	array(
		'default' => 0,
		'transport' => 'refresh',
		'sanitize_callback' => 'ostrich_magazine_switch_sanitization'
	)
);
$wp_customize->add_control( new Ostrich_Magazine_Toggle_Switch_Custom_control( $wp_customize, 'ostrich_magazine_blog_enable',
	array(
		'label' => esc_html__( 'Enable blog section', 'ostrich-magazine' ),
		'section' => 'ostrich_magazine_blog'
	)
) );

$wp_customize->add_setting( 'ostrich_magazine_slider_widget_enable',
	array(
		'default' => 0,
		'transport' => 'refresh',
		'sanitize_callback' => 'ostrich_magazine_switch_sanitization'
	)
);
$wp_customize->add_control( new Ostrich_Magazine_Toggle_Switch_Custom_control( $wp_customize, 'ostrich_magazine_slider_widget_enable',
	array(
		'label' => esc_html__( 'Enable blog section widget', 'ostrich-magazine' ),
		'section' => 'ostrich_magazine_blog',
		'active_callback'	=> 'ostrich_magazine_if_blog_enabled',
	)
) );

// blog enable settings
$wp_customize->add_setting(
	'ostrich_magazine_blog',
	array(
		'sanitize_callback' => 'ostrich_magazine_sanitize_select',
		'default' => 'cat'
	)
);

$wp_customize->add_control(
	'ostrich_magazine_blog',
	array(
		'section'		=> 'ostrich_magazine_blog',
		'label'			=> esc_html__( 'Content type:', 'ostrich-magazine' ),
		'description'			=> esc_html__( 'Choose where you want to render the content from.', 'ostrich-magazine' ),
		'type'			=> 'select',
		'active_callback'	=> 'ostrich_magazine_if_blog_enabled',
		'choices'		=> array( 
				'post' => esc_html__( 'Post', 'ostrich-magazine' ),
				'page' => esc_html__( 'Page', 'ostrich-magazine' ),
				'cat' => esc_html__( 'Category', 'ostrich-magazine' ),
		 	)
	)
);

for ($i=1; $i <= 5 ; $i++) { 
	// blog post setting
	$wp_customize->add_setting(
		'ostrich_magazine_blog_post_'.$i,
		array(
			'sanitize_callback' => 'ostrich_magazine_sanitize_dropdown_pages',
		)
	);

	$wp_customize->add_control(
		'ostrich_magazine_blog_post_'.$i,
		array(
			'section'		=> 'ostrich_magazine_blog',
			'label'			=> esc_html__( 'Post ', 'ostrich-magazine' ).$i,
			'active_callback' => 'ostrich_magazine_if_blog_post',
			'type'			=> 'select',
			'choices'		=> ostrich_magazine_get_post_choices(),
		)
	);

	// blog page setting
	$wp_customize->add_setting(
		'ostrich_magazine_blog_page_'.$i,
		array(
			'sanitize_callback' => 'ostrich_magazine_sanitize_dropdown_pages',
			'default' => 0,
		)
	);

	$wp_customize->add_control(
		'ostrich_magazine_blog_page_'.$i,
		array(
			'section'		=> 'ostrich_magazine_blog',
			'label'			=> esc_html__( 'Page ', 'ostrich-magazine' ).$i,
			'type'			=> 'dropdown-pages',
			'active_callback' => 'ostrich_magazine_if_blog_page'
		)
	);
}

// blog category setting
$wp_customize->add_setting(
	'ostrich_magazine_blog_cat',
	array(
		'sanitize_callback' => 'ostrich_magazine_sanitize_select',
	)
);

$wp_customize->add_control(
	'ostrich_magazine_blog_cat',
	array(
		'section'		=> 'ostrich_magazine_blog',
		'label'			=> esc_html__( 'Category:', 'ostrich-magazine' ),
		'active_callback' => 'ostrich_magazine_if_blog_cat',
		'type'			=> 'select',
		'choices'		=> ostrich_magazine_get_post_cat_choices(),
	)
);
