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

/**
 * Add professionals options to theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function personaltrainer_professionals_options( $wp_customize ) {
    $wp_customize->add_section( 'personaltrainer_professionals', array(
    		'active_callback' => 'personaltrainer_is_professionals_section_enabled',
			'title' => esc_html__( 'Professionals', 'personal-trainer' ),
			'panel' => 'personaltrainer_theme_options',
		)
	);

	$sections_visibility = personaltrainer_section_visibility_options();

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

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_title',
			'default'           => esc_html__( 'Meet Professionals', 'personal-trainer' ),
			'sanitize_callback' => 'wp_kses_post',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'label'             => esc_html__( 'Title', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
			'type'              => 'text',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_description',
			'sanitize_callback' => 'wp_kses_post',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'label'             => esc_html__( 'Description', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
			'type'              => 'textarea',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_disable_image',
			'sanitize_callback' => 'personaltrainer_sanitize_checkbox',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'label'             => esc_html__( 'Check to disable images/Post Thumbnails', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
			'type'              => 'checkbox',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_number',
			'default'           => 3,
			'sanitize_callback' => 'personaltrainer_sanitize_number_range',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'description'       => esc_html__( 'Save and refresh the page this option is changed', 'personal-trainer' ),
			'input_attrs'       => array(
				'style' => 'width: 100px;',
				'min'   => 0,
			),
			'label'             => esc_html__( 'No of items', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
			'type'              => 'number',
			'transport'         => 'postMessage',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_show',
			'default'           => 'hide-content',
			'sanitize_callback' => 'personaltrainer_sanitize_select',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'choices'           => personaltrainer_content_show(),
			'label'             => esc_html__( 'Display Content', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
			'type'              => 'select',
		)
	);

	$number = get_theme_mod( 'personaltrainer_professionals_number', 3 );

	//loop for professionals post content
	for ( $i = 1; $i <= $number ; $i++ ) {
		personaltrainer_register_option( $wp_customize, array(
				'name'              => 'personaltrainer_professionals_page_' . $i,
				'sanitize_callback' => 'personaltrainer_sanitize_post',
				'active_callback'   => 'personaltrainer_is_professionals_active',
				'label'             => esc_html__( 'Page', 'personal-trainer' ) . '&nbsp;' . $i ,
				'section'           => 'personaltrainer_professionals',
				'type'              => 'dropdown-pages',
			)
		);
	} // End for().

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_more_btn_link',
			'default'           => '#',
			'sanitize_callback' => 'esc_url_raw',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'label'             => esc_html__( 'More Button Link', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_more_btn_text',
			'default'           => esc_html__( 'View Full Team', 'personal-trainer' ),
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'label'             => esc_html__( 'Title', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
			'type'              => 'text',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_professionals_more_btn__target',
			'sanitize_callback' => 'personaltrainer_sanitize_checkbox',
			'active_callback'   => 'personaltrainer_is_professionals_active',
			'label'             => esc_html__( 'Check to Open Link in New Window/Tab', 'personal-trainer' ),
			'section'           => 'personaltrainer_professionals',
			'type'              => 'checkbox',
		)
	);
}
add_action( 'customize_register', 'personaltrainer_professionals_options', 10 );

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

		return ( 'disabled' !== $enable );
	}
endif;

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