<?php
/**
 * Hero Content Options
 *
 * @package Personal_Trainer
 */

/**
 * Add hero content options to theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function personaltrainer_hero_content_options( $wp_customize ) {
	$wp_customize->add_section( 'personaltrainer_hero_content_options', array(
			'title' => esc_html__( 'Hero Content', 'personal-trainer' ),
			'panel' => 'personaltrainer_theme_options',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_hero_content_visibility',
			'default'           => 'disabled',
			'sanitize_callback' => 'personaltrainer_sanitize_select',
			'choices'           => personaltrainer_section_visibility_options(),
			'label'             => esc_html__( 'Enable on', 'personal-trainer' ),
			'section'           => 'personaltrainer_hero_content_options',
			'type'              => 'select',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_hero_content',
			'default'           => '0',
			'sanitize_callback' => 'personaltrainer_sanitize_post',
			'active_callback'   => 'personaltrainer_is_hero_content_active',
			'label'             => esc_html__( 'Page', 'personal-trainer' ),
			'section'           => 'personaltrainer_hero_content_options',
			'type'              => 'dropdown-pages',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_disable_hero_content_title',
			'sanitize_callback' => 'personaltrainer_sanitize_checkbox',
			'active_callback'   => 'personaltrainer_is_disable_title_enabled',
			'label'             => esc_html__( 'Check to disable title', 'personal-trainer' ),
			'section'           => 'personaltrainer_hero_content_options',
			'type'              => 'checkbox',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_hero_content_show',
			'default'           => 'excerpt',
			'sanitize_callback' => 'personaltrainer_sanitize_select',
			'active_callback'   => 'personaltrainer_is_hero_content_show_enabled',
			'choices'           => personaltrainer_content_show(),
			'label'             => esc_html__( 'Display Content', 'personal-trainer' ),
			'section'           => 'personaltrainer_hero_content_options',
			'type'              => 'select',
		)
	);
}
add_action( 'customize_register', 'personaltrainer_hero_content_options' );

/** Active Callback Functions **/
if ( ! function_exists( 'personaltrainer_is_hero_content_active' ) ) :
	/**
	* Return true if hero content is active
	*
	* @since Personal Trainer 0.1
	*/
	function personaltrainer_is_hero_content_active( $control ) {
		$enable = $control->manager->get_setting( 'personaltrainer_hero_content_visibility' )->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_disable_title_enabled' ) ) :
	/**
	* @since Personal Trainer 1.2
	*/
	function personaltrainer_is_disable_title_enabled( $control ) {
		$enable = $control->manager->get_setting( 'personaltrainer_disable_hero_content_title' )->value();
		return ( ($enable != '') && (personaltrainer_is_hero_content_active($control)) );
	}
endif;

if( ! function_exists( 'personaltrainer_is_hero_content_show_enabled' ) ) :
	/**
	* @since Personal Trainer 1.2
	*/
	function personaltrainer_is_hero_content_show_enabled( $control ) {
		$enable = $control->manager->get_setting( 'personaltrainer_hero_content_show' )->value();
		return ( ($enable != $control->manager->get_setting( 'personaltrainer_hero_content_show' )->default) && (personaltrainer_is_hero_content_active($control)) );
	}
endif;