<?php
/**
 * Reservation options
 *
 * @package Personal_Trainer
 */

/**
 * Add reservation options to theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function personaltrainer_reservation_options( $wp_customize ) {
    $wp_customize->add_section( 'personaltrainer_reservation', array(
    		'active_callback' 	=>'personaltrainer_is_reservation_section_enabled',
			'title' 			=> esc_html__( 'Reservation', 'personal-trainer' ),
			'panel' 			=> 'personaltrainer_theme_options',
		)
	);

	// Add color scheme setting and control.
	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_reservation_option',
			'default'           => 'disabled',
			'sanitize_callback' => 'personaltrainer_sanitize_select',
			'choices'           => personaltrainer_section_visibility_options(),
			'label'             => esc_html__( 'Enable on', 'personal-trainer' ),
			'section'           => 'personaltrainer_reservation',
			'type'              => 'select',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_reservation_position',
			'sanitize_callback' => 'personaltrainer_sanitize_checkbox',
			'active_callback'   => 'personaltrainer_is_reservation_active',
			'label'             => esc_html__( 'Check to Move below content', 'personal-trainer' ),
			'section'           => 'personaltrainer_reservation',
			'type'              => 'checkbox',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_reservation_title',
			'default'           => esc_html__( 'Reservation', 'personal-trainer' ),
			'sanitize_callback' => 'wp_kses_data',
			'active_callback'   => 'personaltrainer_is_reservation_active',
			'label'             => esc_html__( 'Title', 'personal-trainer' ),
			'section'           => 'personaltrainer_reservation',
			'type'              => 'text',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_reservation_description',
			'default'           => wp_kses_data( __( 'Begin today with <span class="bold">2 weeks</span> of <span class="italic">unlimited yoga</span> and <span class="italic">movement</span> classes for <span class="bold">$25</span>', 'personal-trainer' ) ),
			'sanitize_callback' => 'wp_kses_data',
			'active_callback'   => 'personaltrainer_is_reservation_active',
			'label'             => esc_html__( 'Description', 'personal-trainer' ),
			'section'           => 'personaltrainer_reservation',
			'type'              => 'textarea',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_reservation_page',
			'sanitize_callback' => 'personaltrainer_sanitize_post',
			'active_callback'   => 'personaltrainer_is_reservation_active',
			'label'             => esc_html__( 'Page', 'personal-trainer' ),
			'section'           => 'personaltrainer_reservation',
			'type'              => 'dropdown-pages',
		)
	);
}
add_action( 'customize_register', 'personaltrainer_reservation_options', 10 );

/** Active Callback Functions **/
if ( ! function_exists( 'personaltrainer_is_reservation_active' ) ) :
	/**
	* Return true if reservation is active
	*
	* @since Personal Trainer 0.1
	*/
	function personaltrainer_is_reservation_active( $control ) {
		$enable = $control->manager->get_setting( 'personaltrainer_reservation_option' )->value();

		//return true only if previewed page on customizer matches the type of content option selected
		return ( personaltrainer_check_section( $enable ) );
	}
endif;

if( ! function_exists( 'personaltrainer_is_reservation_section_enabled' ) ) :
	/**
	* Return true if reservation section is enabled
	*
	* @since Personal Trainer 1.2
	*/
	function personaltrainer_is_reservation_section_enabled( $control ) {
		$enable = $control->manager->get_setting( 'personaltrainer_reservation_option' )->value();
		return ( ($enable != $control->manager->get_setting( 'personaltrainer_reservation_option' )->default) );
	}
endif;