<?php
/**
 * Contact Info Footer options
 *
 * @package Personal_Trainer
 */

/**
 * Add contact options to theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function personaltrainer_footer_contact_options( $wp_customize ) {
    $wp_customize->add_section( 'personaltrainer_footer_contact', array(
    		'active_callback' => 'personaltrainer_is_footer_contact_enabled',
			'title'       => esc_html__( 'Footer Contact', 'personal-trainer' ),
			'description' => esc_html__( 'Contact Information above Footer', 'personal-trainer' ),
			'panel'       => 'personaltrainer_theme_options',
		)
	);

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

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_footer_contact_page',
			'sanitize_callback' => 'personaltrainer_sanitize_post',
			'active_callback'   => 'personaltrainer_is_contact_active',
			'label'             => esc_html__( 'Page', 'personal-trainer' ),
			'section'           => 'personaltrainer_footer_contact',
			'type'              => 'dropdown-pages',
		)
	);

	personaltrainer_register_option( $wp_customize, array(
			'name'              => 'personaltrainer_footer_contact_image_link',
			'sanitize_callback' => 'esc_url_raw',
			'active_callback'   => 'personaltrainer_is_contact_active',
			'label'             => esc_html__( 'Post/Page Thumbnail Link', 'personal-trainer' ),
			'section'           => 'personaltrainer_footer_contact',
			'type'              => 'url',
		)
	);
}
add_action( 'customize_register', 'personaltrainer_footer_contact_options', 10 );

/** Active Callback Functions **/
if ( ! function_exists( 'personaltrainer_is_contact_active' ) ) :
	/**
	* Return true if contact is active
	*
	* @since Personal Trainer 0.1
	*/
	function personaltrainer_is_contact_active( $control ) {
		$enable = $control->manager->get_setting( 'personaltrainer_footer_contact_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_footer_contact_enabled' ) ) :
	/**
	* Return true if header top is enabled
	*
	* @since Personal Trainer 1.2
	*/
	function personaltrainer_is_footer_contact_enabled( $control ) {
		$enable = $control->manager->get_setting( 'personaltrainer_footer_contact_option' )->value();
		return ( ($enable != $control->manager->get_setting( 'personaltrainer_footer_contact_option' )->default) );
	}
endif;
