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

/**
 * Add Header Media options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function signify_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 ', 'signify-pro' );

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

	/*Overlay Option for Header Media*/
	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_image_opacity',
			'default'           => '0',
			'sanitize_callback' => 'signify_sanitize_number_range',
			'label'             => esc_html__( 'Header Media Overlay', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'number',
			'input_attrs'       => array(
				'style' => 'width: 60px;',
				'min'   => 0,
				'max'   => 100,
			),
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_text_alignment',
			'default'           => 'text-align-left',
			'sanitize_callback' => 'signify_sanitize_select',
			'choices'           => array(
				'text-align-center' => esc_html__( 'Center', 'signify-pro' ),
				'text-align-right'  => esc_html__( 'Right', 'signify-pro' ),
				'text-align-left'   => esc_html__( 'Left', 'signify-pro' ),
			),
			'label'             => esc_html__( 'Text Alignment', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_content_alignment',
			'default'           => 'content-align-left',
			'sanitize_callback' => 'signify_sanitize_select',
			'choices'           => array(
				'content-align-center' => esc_html__( 'Center', 'signify-pro' ),
				'content-align-right'  => esc_html__( 'Right', 'signify-pro' ),
				'content-align-left'   => esc_html__( 'Left', 'signify-pro' ),
			),
			'label'             => esc_html__( 'Content Alignment', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_logo',
			'sanitize_callback' => 'esc_url_raw',
			'custom_control'    => 'WP_Customize_Image_Control',
			'label'             => esc_html__( 'Header Media Logo', 'signify-pro' ),
			'section'           => 'header_image',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_logo_option',
			'default'           => 'homepage',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_header_media_logo_active',
			'choices'           => array(
				'homepage'               => esc_html__( 'Homepage / Frontpage', 'signify-pro' ),
				'entire-site'            => esc_html__( 'Entire Site', 'signify-pro' ) ),
			'label'             => esc_html__( 'Enable Header Media logo on', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_subtitle',
			'sanitize_callback' => 'wp_kses_post',
			'active_callback' 	=> 'is_front_page',
			'label'             => esc_html__( 'Header Media Subtitle', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'text',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_title',
			'sanitize_callback' => 'wp_kses_post',
			'label'             => esc_html__( 'Header Media Title', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'text',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_title_position',
			'default'           => 'on-header-image',
			'sanitize_callback' => 'signify_sanitize_select',
			'label'             => esc_html__( 'Title Position for single Page/Post', 'signify-pro' ),
			'description'       => esc_html__( 'Only Applicable if header image is enabled.', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'select',
			'choices'           => array(
				'on-header-image'    => esc_html__( 'On Header Image', 'signify-pro' ),
				'below-header-image' => esc_html__( 'Below Header Image', 'signify-pro' ),
			),
		)
	);

    signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_text',
			'sanitize_callback' => 'wp_kses_post',
			'label'             => esc_html__( 'Site Header Text', 'signify-pro' ),
			'section'           => 'header_image',
			'type'              => 'textarea',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_url',
			'sanitize_callback' => 'esc_url_raw',
			'label'             => esc_html__( 'Header Media Url', 'signify-pro' ),
			'section'           => 'header_image',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_media_url_text',
			'sanitize_callback' => 'sanitize_text_field',
			'label'             => esc_html__( 'Header Media Url Text', 'signify-pro' ),
			'section'           => 'header_image',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_header_url_target',
			'sanitize_callback' => 'signify_sanitize_checkbox',
			'label'             => esc_html__( 'Open Link in New Window/Tab', 'signify-pro' ),
			'section'           => 'header_image',
			'type'    			=> 'checkbox',
		)
	);
}
add_action( 'customize_register', 'signify_header_media_options' );

/** Active Callback Functions */

if ( ! function_exists( 'signify_is_header_media_logo_active' ) ) :
	/**
	* Return true if header logo is active
	*
	* @since 1.0.0
	*/
	function signify_is_header_media_logo_active( $control ) {
		$logo = $control->manager->get_setting( 'signify_header_media_logo' )->value();
		if ( '' != $logo ) {
			return true;
		} else {
			return false;
		}
	}
endif;
