<?php
/**
 * Team options
 *
 * @package SimClick
 */

/**
 * Add team content options to theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function signify_team_options( $wp_customize ) {

	$wp_customize->add_section( 'signify_team', array(
			'title' => esc_html__( 'Team', 'signify-pro' ),
			'panel' => 'signify_theme_options',
		)
	);

	// Add color scheme setting and control.
	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_option',
			'default'           => 'disabled',
			'sanitize_callback' => 'signify_sanitize_select',
			'choices'           => signify_section_visibility_options(),
			'label'             => esc_html__( 'Enable on', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_layout',
			'default'           => 'layout-four',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_team_active',
			'choices'           => signify_sections_layout_options(),
			'label'             => esc_html__( 'Select Featured Content Layout', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'              => 'select',
		)
	);

	signify_section_header_options( 'signify_team', 'team', 'signify_is_team_active' );

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_type',
			'default'           => 'category',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_team_active',
			'choices'           => signify_section_type_options(),
			'label'             => esc_html__( 'Type', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'              => 'select',
		)
	);

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

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_number',
			'default'           => 4,
			'sanitize_callback' => 'signify_sanitize_number_range',
			'active_callback'   => 'signify_is_team_active',
			'description'       => esc_html__( 'Save and refresh the page if No. of Items is changed', 'signify-pro' ),
			'input_attrs'       => array(
				'style' => 'width: 100px;',
				'min'   => 0,
			),
			'label'             => esc_html__( 'No of Items', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'              => 'number',
			'transport'         => 'postMessage',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_show',
			'default'           => 'excerpt',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_team_post_page_category_content_active',
			'choices'           => signify_content_show(),
			'label'             => esc_html__( 'Display Content', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_meta_show',
			'default'           => 'hide-meta',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_team_post_page_category_content_active',
			'choices'           => signify_meta_show(),
			'label'             => esc_html__( 'Display Meta', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'              => 'select',
		)
	);


	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_select_category',
			'sanitize_callback' => 'signify_sanitize_category_list',
			'custom_control'    => 'Signify_Multi_Cat',
			'active_callback'   => 'signify_is_team_category_content_active',
			'label'             => esc_html__( 'Select Categories', 'signify-pro' ),
			'name'              => 'signify_team_select_category',
			'section'           => 'signify_team',
			'type'              => 'dropdown-categories',
		)
	);

	$number = get_theme_mod( 'signify_team_number', 4 );

	//loop for team post content
	for ( $i = 1; $i <= $number ; $i++ ) {
		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_post_' . $i,
				'sanitize_callback' => 'signify_sanitize_post',
				'default'           => 0,
				'active_callback'   => 'signify_is_team_post_content_active',
				'input_attrs'       => array(
					'style'             => 'width: 40px;'
				),
				'label'             => esc_html__( 'Post', 'signify-pro' ) . ' ' . $i ,
				'section'           => 'signify_team',
				'choices'           => signify_generate_post_array(),
				'type'              => 'select'
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_page_' . $i,
				'sanitize_callback' => 'signify_sanitize_post',
				'active_callback'   => 'signify_is_team_page_content_active',
				'label'             => esc_html__( 'Team Page', 'signify-pro' ) . ' ' . $i ,
				'section'           => 'signify_team',
				'type'              => 'dropdown-pages',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_note_' . $i,
				'sanitize_callback' => 'sanitize_text_field',
				'custom_control'    => 'signify_Note_Control',
				'active_callback'   => 'signify_is_team_image_content_active',
				'label'             => esc_html__( 'Team #', 'signify-pro' ) .  $i,
				'section'           => 'signify_team',
				'type'              => 'description',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_image_' . $i,
				'sanitize_callback' => 'signify_sanitize_image',
				'custom_control'    => 'WP_Customize_Image_Control',
				'active_callback'   => 'signify_is_team_image_content_active',
				'label'             => esc_html__( 'Image', 'signify-pro' ),
				'section'           => 'signify_team',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_link_' . $i,
				'sanitize_callback' => 'esc_url_raw',
				'active_callback'   => 'signify_is_team_image_content_active',
				'label'             => esc_html__( 'Link', 'signify-pro' ),
				'section'           => 'signify_team',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_target_' . $i,
				'sanitize_callback' => 'signify_sanitize_checkbox',
				'active_callback'   => 'signify_is_team_image_content_active',
				'label'             => esc_html__( 'Open Link in New Window/Tab', 'signify-pro' ),
				'section'           => 'signify_team',
				'type'    			=> 'checkbox',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_title_' . $i,
				'sanitize_callback' => 'sanitize_text_field',
				'active_callback'   => 'signify_is_team_image_content_active',
				'label'             => esc_html__( 'Title', 'signify-pro' ),
				'section'           => 'signify_team',
				'type'              => 'text',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_position_' . $i,
				'sanitize_callback' => 'sanitize_text_field',
				'active_callback'   => 'signify_is_team_image_content_active',
				'label'             => esc_html__( 'Position', 'signify-pro' ),
				'section'           => 'signify_team',
				'type'              => 'text',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_content_' . $i,
				'sanitize_callback' => 'wp_kses_post',
				'active_callback'   => 'signify_is_team_image_content_active',
				'label'             => esc_html__( 'Content', 'signify-pro' ),
				'section'           => 'signify_team',
				'type'              => 'textarea',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_social_link_one_' . $i,
				'sanitize_callback' => 'esc_url_raw',
				'active_callback'   => 'signify_is_team_active',
				'label'             => esc_html__( 'Team #', 'signify-pro' ) .  $i . esc_html__( ': Social Link #1', 'signify-pro' ),
				'section'           => 'signify_team',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_social_link_two_' . $i,
				'sanitize_callback' => 'esc_url_raw',
				'active_callback'   => 'signify_is_team_active',
				'label'             => esc_html__( 'Team #', 'signify-pro' ) .  $i . esc_html__( ': Social Link #2', 'signify-pro' ),
				'section'           => 'signify_team',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_social_link_three_' . $i,
				'sanitize_callback' => 'esc_url_raw',
				'active_callback'   => 'signify_is_team_active',
				'label'             => esc_html__( 'Team #', 'signify-pro' ) .  $i . esc_html__( ': Social Link #3', 'signify-pro' ),
				'section'           => 'signify_team',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_team_social_link_four_' . $i,
				'sanitize_callback' => 'esc_url_raw',
				'active_callback'   => 'signify_is_team_active',
				'label'             => esc_html__( 'Team #', 'signify-pro' ) .  $i . esc_html__( ': Social Link #4', 'signify-pro' ),
				'section'           => 'signify_team',
			)
		);
	} // End for().

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_text',
			'default'           => esc_html__( 'View All', 'signify-pro' ),
			'sanitize_callback' => 'sanitize_text_field',
			'active_callback'   => 'signify_is_team_active',
			'label'             => esc_html__( 'Button Text', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'              => 'text',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_link',
			'sanitize_callback' => 'esc_url_raw',
			'active_callback'   => 'signify_is_team_active',
			'label'             => esc_html__( 'Button Link', 'signify-pro' ),
			'section'           => 'signify_team',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_team_target',
			'sanitize_callback' => 'signify_sanitize_checkbox',
			'active_callback'   => 'signify_is_team_active',
			'label'             => esc_html__( 'Open Link in New Window/Tab', 'signify-pro' ),
			'section'           => 'signify_team',
			'type'    			=> 'checkbox',
		)
	);
}
add_action( 'customize_register', 'signify_team_options', 10 );

/** Active Callback Functions **/
if ( ! function_exists( 'signify_is_team_active' ) ) :
	/**
	* Return true if team content is active
	*
	* @since 1.0.0
	*/
	function signify_is_team_active( $control ) {
		$enable = $control->manager->get_setting( 'signify_team_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_team_post_content_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_team_post_content_active( $control ) {
		$type = $control->manager->get_setting( 'signify_team_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_team_active( $control ) && ( 'post' === $type ) );
	}
endif;

if ( ! function_exists( 'signify_is_team_page_content_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_team_page_content_active( $control ) {
		$type = $control->manager->get_setting( 'signify_team_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_team_active( $control ) && ( 'page' === $type ) );
	}
endif;

if ( ! function_exists( 'signify_is_team_category_content_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_team_category_content_active( $control ) {
		$type = $control->manager->get_setting( 'signify_team_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_team_active( $control ) && ( 'category' === $type ) );
	}
endif;

if ( ! function_exists( 'signify_is_team_post_page_category_content_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_team_post_page_category_content_active( $control ) {
		$type = $control->manager->get_setting( 'signify_team_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_team_active( $control ) && ( 'category' === $type || 'page' === $type || 'post' === $type ) );
	}
endif;

if ( ! function_exists( 'signify_is_team_image_content_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_team_image_content_active( $control ) {
		$type = $control->manager->get_setting( 'signify_team_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_team_active( $control ) && ( 'custom' === $type ) );
	}
endif;

if ( ! function_exists( 'signify_is_team_bg_active' ) ) :
    /**
    * Return true if background is set
    *
    * @since SimClick Pro 1.0
    */
    function signify_is_team_bg_active( $control ) {
        $bg_image = $control->manager->get_setting( 'signify_team_bg_image' )->value();

        return ( signify_is_team_active( $control ) && '' !== $bg_image );
    }
endif;
