<?php
/**
 * Courses Section options.
 *
 * @package Equestrian Club
 */

$default = equestrian_club_get_default_theme_options();

// Courses Section
$wp_customize->add_section( 'section_featured_courses',
	array(
	'title'      => __( 'Courses Section', 'equestrian-club' ),
	'priority'   => 100,
	'capability' => 'edit_theme_options',
	'panel'      => 'home_page_panel',
	)
);

// Enable Section
$wp_customize->add_setting('theme_options[enable_featured_courses_section]', 
	array(
	'default' 			=> $default['enable_featured_courses_section'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'equestrian_club_sanitize_checkbox'
	)
);

$wp_customize->add_control('theme_options[enable_featured_courses_section]', 
	array(		
	'label' 	=> __('Enable Section', 'equestrian-club'),
	'section' 	=> 'section_featured_courses',
	'settings'  => 'theme_options[enable_featured_courses_section]',
	'type' 		=> 'checkbox',	
	)
);

// Items
$wp_customize->add_setting('theme_options[number_of_featured_courses_items]', 
	array(
	'default' 			=> $default['number_of_featured_courses_items'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'equestrian_club_sanitize_number_range'
	)
);

$wp_customize->add_control('theme_options[number_of_featured_courses_items]', 
	array(
	'label'       => __('Items (Max: 6)', 'equestrian-club'),
	'section'     => 'section_featured_courses',   
	'settings'    => 'theme_options[number_of_featured_courses_items]',		
	'type'        => 'number',
	'active_callback' => 'equestrian_club_featured_courses_active',
	'input_attrs' => array(
			'min'	=> 1,
			'max'	=> 6,
			'step'	=> 1,
		),
	)
);

// Section Title
$wp_customize->add_setting('theme_options[featured_courses_section_title]', 
	array(
	'default'           => $default['featured_courses_section_title'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'sanitize_text_field'
	)
);

$wp_customize->add_control('theme_options[featured_courses_section_title]', 
	array(
	'label'       => __('Section Title', 'equestrian-club'),
	'section'     => 'section_featured_posts',   
	'settings'    => 'theme_options[featured_courses_section_title]',	
	'active_callback' => 'equestrian_club_featured_posts_active',		
	'type'        => 'text'
	)
);

// Section Second Title
$wp_customize->add_setting('theme_options[featured_courses_section_2_title]', 
	array(
	'default'           => $default['featured_courses_section_2_title'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'sanitize_text_field'
	)
);

$wp_customize->add_control('theme_options[featured_courses_section_2_title]', 
	array(
	'label'       => __('Section Second Title', 'equestrian-club'),
	'section'     => 'section_featured_posts',   
	'settings'    => 'theme_options[featured_courses_section_2_title]',	
	'active_callback' => 'equestrian_club_featured_posts_active',		
	'type'        => 'text'
	)
);

// Column
$wp_customize->add_setting('theme_options[featured_courses_column]', 
	array(
	'default' 			=> $default['featured_courses_column'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'equestrian_club_sanitize_select'
	)
);

$wp_customize->add_control(new equestrian_club_Image_Radio_Control($wp_customize, 'theme_options[featured_courses_column]', 
	array(		
	'label' 	=> __('Column', 'equestrian-club'),
	'section' 	=> 'section_featured_courses',
	'settings'  => 'theme_options[featured_courses_column]',
	'type' 		=> 'radio-image',
	'active_callback' => 'equestrian_club_featured_courses_active',
	'choices' 	=> array(		
		'col-1' 	=> esc_url(get_template_directory_uri()) . '/assets/images/column-1.jpg',						
		'col-2' 	=> esc_url(get_template_directory_uri()) . '/assets/images/column-2.jpg',
		'col-3' 	=> esc_url(get_template_directory_uri()) . '/assets/images/column-3.jpg',
		'col-4' 	=> esc_url(get_template_directory_uri()) . '/assets/images/column-4.jpg',
		'col-5' 	=> esc_url(get_template_directory_uri()) . '/assets/images/column-5.jpg',
		'col-6' 	=> esc_url(get_template_directory_uri()) . '/assets/images/column-6.jpg',
		),	
	))
);

// Content Type
$wp_customize->add_setting('theme_options[featured_courses_content_type]', 
	array(
	'default' 			=> $default['featured_courses_content_type'],
	'type'              => 'theme_mod',
	'capability'        => 'edit_theme_options',	
	'sanitize_callback' => 'equestrian_club_sanitize_select'
	)
);

$wp_customize->add_control('theme_options[featured_courses_content_type]', 
	array(
	'label'       => __('Content Type', 'equestrian-club'),
	'section'     => 'section_featured_courses',   
	'settings'    => 'theme_options[featured_courses_content_type]',		
	'type'        => 'select',
	'active_callback' => 'equestrian_club_featured_courses_active',
	'choices'	  => array(
			'featured_courses_page'	  => __('Page','equestrian-club'),
			'featured_courses_post'	  => __('Post','equestrian-club'),
		),
	)
);

$number_of_featured_courses_items = equestrian_club_get_option( 'number_of_featured_courses_items' );

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

	// Page
	$wp_customize->add_setting('theme_options[featured_courses_page_'.$i.']', 
		array(
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',	
		'sanitize_callback' => 'equestrian_club_dropdown_pages'
		)
	);
	
	$wp_customize->add_control('theme_options[featured_courses_page_'.$i.']', 
		array(
		'label'       => sprintf( __('Page #%1$s', 'equestrian-club'), $i),
		'section'     => 'section_featured_courses',   
		'settings'    => 'theme_options[featured_courses_page_'.$i.']',		
		'type'        => 'dropdown-pages',
		'active_callback' => 'equestrian_club_featured_courses_page',
		)
	);

	// Post
	$wp_customize->add_setting('theme_options[featured_courses_post_'.$i.']', 
		array(
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',	
		'sanitize_callback' => 'equestrian_club_dropdown_pages'
		)
	);

	$wp_customize->add_control('theme_options[featured_courses_post_'.$i.']', 
		array(
		'label'       => sprintf( __('Post #%1$s', 'equestrian-club'), $i),
		'section'     => 'section_featured_courses',   
		'settings'    => 'theme_options[featured_courses_post_'.$i.']',		
		'type'        => 'select',
		'choices'	  => equestrian_club_dropdown_posts(),
		'active_callback' => 'equestrian_club_featured_courses_post',
		)
	);
}