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

/**
 * Add Contact options to theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function signify_contact_options( $wp_customize ) {
    $wp_customize->add_section( 'signify_contact', array(
			'title' => esc_html__( 'Contact', 'signify-pro' ),
			'panel' => 'signify_theme_options',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_bg_image',
			'sanitize_callback' => 'signify_sanitize_image',
			'active_callback'   => 'signify_is_contact_active',
			'custom_control'    => 'WP_Customize_Image_Control',
			'label'             => esc_html__( 'Background Image', 'signify-pro' ),
			'section'           => 'signify_contact',
		)
	);

	signify_section_header_options( 'signify_contact', 'contact_info', 'signify_is_contact_active' );

	// Contact Info Start.
	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_left_note',
			'sanitize_callback' => 'sanitize_text_field',
			'custom_control'    => 'Signify_Note_Control',
			'label'             => esc_html__( 'Contact Info( Left Section )', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'description',
        )
    );

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_info_option',
			'default'           => 'disabled',
			'sanitize_callback' => 'signify_sanitize_select',
			'choices'           => signify_section_visibility_options(),
			'label'             => esc_html__( 'Enable Contact Info on', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'select',
		)
	);

signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_email_label',
			'default'           => esc_html__( 'Email', 'signify-pro' ),
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Email Label', 'signify-pro' ),
			'section'           => 'signify_contact',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_email',
			'default'           => 'someone@somewhere.com',
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Email', 'signify-pro' ),
			'section'           => 'signify_contact',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_phone_label',
			'default'           => esc_html__( 'Phone', 'signify-pro' ),
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Phone Label', 'signify-pro' ),
			'section'           => 'signify_contact',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_phone',
			'default'           => '123-456-7890',
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Phone', 'signify-pro' ),
			'section'           => 'signify_contact',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_address_label',
			'default'           => esc_html__( 'Location', 'signify-pro' ),
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Address Label', 'signify-pro' ),
			'section'           => 'signify_contact',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_address',
			'default'           => 'Boston, MA, USA',
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Address', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'textarea',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_address_link',
			'default'			=> '#',
			'sanitize_callback' => 'esc_url_raw',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Address Link', 'signify-pro' ),
			'section'           => 'signify_contact',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_address_target',
			'sanitize_callback' => 'signify_sanitize_checkbox',
			'active_callback'   => 'signify_is_contact_info_active',
			'label'             => esc_html__( 'Open Link in New Window/Tab', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'   			=> 'checkbox',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_info_note',
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_info_active',
			'custom_control'    => 'Signify_Note_Control',
			'label'             => sprintf( esc_html__( 'Click %1$shere%2$s to set Social Menu', 'signify-pro' ),
                '<a href="javascript:wp.customize.control( \'nav_menu_locations[social-contact]\' ).focus();">',
                 '</a>'
            ),
			'section'           => 'signify_contact',
			'type'              => 'description',
        )
    );
	// Contact Info End.

	// Contact Form Start.
	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_right_note',
			'sanitize_callback' => 'sanitize_text_field',
			'custom_control'    => 'Signify_Note_Control',
			'label'             => esc_html__( 'Contact Form( Right Section )', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'description',
        )
    );
	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_option',
			'default'           => 'disabled',
			'sanitize_callback' => 'signify_sanitize_select',
			'choices'           => signify_section_visibility_options(),
			'label'             => esc_html__( 'Enable Contact Form on', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'select',
		)
	);

	$type = signify_section_type_options();

	unset( $type['category'] );

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_type',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_contact_form_active',
            'choices'           => $type,
			'label'             => esc_html__( 'Type', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_title',
			'default'           => esc_html__( 'Send us Message', 'signify-pro' ),
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_contact_form_active',
			'label'             => esc_html__( 'Title', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'text',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_post',
			'sanitize_callback' => 'signify_sanitize_post',
			'default'           => 0,
			'active_callback'   => 'signify_is_contact_post_active',
			'input_attrs'       => array(
				'style' => 'width: 40px;'
			),
			'label'             => esc_html__( 'Post', 'signify-pro' ),
			'section'           => 'signify_contact',
			'choices'           => signify_generate_post_array(),
			'type'              => 'select'
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_page',
			'sanitize_callback' => 'signify_sanitize_post',
			'active_callback'   => 'signify_is_contact_page_active',
			'label'             => esc_html__( 'Page', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'dropdown-pages',
			'allow_addition'    => true,
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_contact_custom',
			'sanitize_callback' => 'wp_kses_post',
			'description'       => esc_html__( 'Add custom shortcodes from Contact Form 7 or Jetpack', 'signify-pro' ),
			'active_callback'   => 'signify_is_contact_custom_active',
			'label'             => esc_html__( 'Custom Content', 'signify-pro' ),
			'section'           => 'signify_contact',
			'type'              => 'textarea',
		)
	);
	// Reservation Form End.
}
add_action( 'customize_register', 'signify_contact_options', 10 );

/** Active Callback Functions **/
if ( ! function_exists( 'signify_is_contact_active' ) ) :
	/**
	* Return true if reservation is active
	*
	* @since 1.0.0
	*/
	function signify_is_contact_active( $control ) {
		$enable_info = $control->manager->get_setting( 'signify_contact_info_option' )->value();
		$enable_form = $control->manager->get_setting( 'signify_contact_option' )->value();

		return ( signify_check_section( $enable_info ) || signify_check_section( $enable_form ) );
	}
endif;

if ( ! function_exists( 'signify_is_contact_info_active' ) ) :
	/**
	* Return true if reservation is active
	*
	* @since 1.0.0
	*/
	function signify_is_contact_info_active( $control ) {
		$enable = $control->manager->get_setting( 'signify_contact_info_option' )->value();

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

if ( ! function_exists( 'signify_is_contact_form_active' ) ) :
	/**
	* Return true if reservation is active
	*
	* @since 1.0.0
	*/
	function signify_is_contact_form_active( $control ) {
		$enable = $control->manager->get_setting( 'signify_contact_option' )->value();

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

if ( ! function_exists( 'signify_is_contact_post_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_contact_post_active( $control ) {
		$type = $control->manager->get_setting( 'signify_contact_type' )->value();

		//return true only if previewed page on customizer matches the type of content option selected and is or is not selected type
		return ( signify_is_contact_form_active( $control ) && 'post' === $type );
	}
endif;

if ( ! function_exists( 'signify_is_contact_page_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_contact_page_active( $control ) {
		$type = $control->manager->get_setting( 'signify_contact_type' )->value();

		//return true only if previewed page on customizer matches the type of content option selected and is or is not selected type
		return ( signify_is_contact_form_active( $control ) && 'page' === $type );
	}
endif;

if ( ! function_exists( 'signify_is_contact_custom_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_contact_custom_active( $control ) {
		$type = $control->manager->get_setting( 'signify_contact_type' )->value();

		//return true only if previewed page on customizer matches the type of content option selected and is or is not selected type
		return ( signify_is_contact_form_active( $control ) && 'custom' === $type );
	}
endif;
