<?php
/**
 * Header Media Options
 *
 * @package Personal_Trainer
 */

/**
 * Add Header Media options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function personaltrainer_header_media_options( $wp_customize ) {
	$wp_customize->get_section( 'header_image' )->description = esc_html__( 'If you add video, it will only show up on Homepage/FrontPage. Other Pages will use Header/Post/Page Image depending on your selection of option. Header Image will be used as a fallback while the video loads ', 'personal-trainer' );

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_header_media_option',
			'default'           => 'exclude-home-page-post',
			'sanitize_callback' => 'personaltrainer_sanitize_select',
			'choices'           => array(
				'homepage'               => esc_html__( 'Homepage / Frontpage', 'personal-trainer' ),
				'exclude-home'           => esc_html__( 'Excluding Homepage', 'personal-trainer' ),
				'exclude-home-page-post' => esc_html__( 'Excluding Homepage, Page/Post Featured Image', 'personal-trainer' ),
				'entire-site'            => esc_html__( 'Entire Site', 'personal-trainer' ),
				'entire-site-page-post'  => esc_html__( 'Entire Site, Page/Post Featured Image', 'personal-trainer' ),
				'pages-posts'            => esc_html__( 'Pages and Posts', 'personal-trainer' ),
				'disable'                => esc_html__( 'Disabled', 'personal-trainer' ),
			),
			'label'             => esc_html__( 'Enable on', 'personal-trainer' ),
			'section'           => 'header_image',
			'type'              => 'select',
			'priority'          => 1,
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_header_media_title',
			'sanitize_callback' => 'wp_kses_post',
			'label'             => esc_html__( 'Header Media Title', 'personal-trainer' ),
			'section'           => 'header_image',
			'type'              => 'text',
		)
	);

    personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_header_media_text',
			'sanitize_callback' => 'wp_kses_post',
			'active_callback'   => 'personaltrainer_is_header_media_text_enabled',
			'label'             => esc_html__( 'Header Media Text', 'personal-trainer' ),
			'section'           => 'header_image',
			'type'              => 'textarea',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_header_media_url',
			'default'           => '',
			'sanitize_callback' => 'esc_url_raw',
			'active_callback'   => 'personaltrainer_is_header_media_url_enabled',
			'label'             => esc_html__( 'Header Media Url', 'personal-trainer' ),
			'section'           => 'header_image',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_header_media_url_text',
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'personaltrainer_is_header_media_url_text_enabled',
			'label'             => esc_html__( 'Header Media Url Text', 'personal-trainer' ),
			'section'           => 'header_image',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_header_url_target',
			'sanitize_callback' => 'personaltrainer_sanitize_checkbox',
			'active_callback'	=> 'personaltrainer_is_header_url_target_enabled',
			'label'             => esc_html__( 'Check to Open Link in New Window/Tab', 'personal-trainer' ),
			'section'           => 'header_image',
			'type'              => 'checkbox',
		)
	);
}
add_action( 'customize_register', 'personaltrainer_header_media_options' );

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

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

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

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