<?php
/**
 * Featured Slider Options
 *
 * @package Signify
 */

/**
 * Add hero content options to theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function signify_logo_slider_options( $wp_customize ) {
	$wp_customize->add_section( 'signify_logo_slider', array(
			'panel' => 'signify_theme_options',
			'title' => esc_html__( 'Logo Slider', 'signify-pro' ),
		)
	);

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

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_layout',
			'default'           => 5,
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_logo_slider_active',
			'choices'           => array(
				'1' => esc_html__( '1 column', 'signify-pro' ),
				'2' => esc_html__( '2 columns', 'signify-pro' ),
				'3' => esc_html__( '3 columns', 'signify-pro' ),
				'4' => esc_html__( '4 columns', 'signify-pro' ),
				'5' => esc_html__( '5 columns', 'signify-pro' ),
			),
			'label'             => esc_html__( 'Select Layout', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'              => 'select',
		)
	);

	signify_section_header_options( 'signify_logo_slider', 'logo_slider', 'signify_is_logo_slider_active' );

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_transition_in',
			'default'           => 'default',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_logo_slider_layout_1',
			'choices'           => signify_transition_effects(),
			'label'             => esc_html__( 'Transition In', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_transition_out',
			'default'           => 'default',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_logo_slider_layout_1',
			'choices'           => signify_transition_effects(),
			'label'             => esc_html__( 'Transition Out', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'              => 'select',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_nav',
			'sanitize_callback' => 'signify_sanitize_checkbox',
			'active_callback'   => 'signify_is_logo_slider_active',
			'label'             => esc_html__( 'Display nav arrows', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'    			=> 'checkbox',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_dots',
			'sanitize_callback' => 'signify_sanitize_checkbox',
			'active_callback'   => 'signify_is_logo_slider_active',
			'label'             => esc_html__( 'Display nav dots', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'    			=> 'checkbox',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_autoplay',
			'default'           => 1,
			'sanitize_callback' => 'signify_sanitize_checkbox',
			'active_callback'   => 'signify_is_logo_slider_active',
			'label'             => esc_html__( 'Autoplay', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'    			=> 'checkbox',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_loop',
			'sanitize_callback' => 'signify_sanitize_checkbox',
			'active_callback'   => 'signify_is_logo_slider_active',
			'label'             => esc_html__( 'loop (Last to first)', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'    			=> 'checkbox',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_transition_timeout',
			'default'           => 4,
			'sanitize_callback' => 'signify_sanitize_number_range',
			'active_callback'   => 'signify_is_logo_slider_active',
			'input_attrs'       => array(
				'style' => 'width: 100px;',
				'min'   => 0,
			),
			'label'             => esc_html__( 'Transition timeout', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'              => 'number',
		)
	);

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

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_number',
			'default'           => '6',
			'sanitize_callback' => 'signify_sanitize_number_range',

			'active_callback'   => 'signify_is_logo_slider_active',
			'description'       => esc_html__( 'Save and refresh the page if No. of Items is changed (Max no of slides is 20)', 'signify-pro' ),
			'input_attrs'       => array(
				'style' => 'width: 100px;',
				'min'   => 0,
				'max'   => 20,
				'step'  => 1,
			),
			'label'             => esc_html__( 'No of Items', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'              => 'number',
		)
	);

	signify_register_option( $wp_customize, array(
			'name'              => 'signify_logo_slider_content_show',
			'default'           => 'hide-content',
			'sanitize_callback' => 'signify_sanitize_select',
			'active_callback'   => 'signify_is_image_logo_slider_inactive',
			'choices'           => signify_content_show(),
			'label'             => esc_html__( 'Display Content', 'signify-pro' ),
			'section'           => 'signify_logo_slider',
			'type'              => 'select',
		)
	);

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

	$logo_slider_number = get_theme_mod( 'signify_logo_slider_number', 6 );

	for ( $i = 1; $i <= $logo_slider_number ; $i++ ) {
		// Post Sliders
		signify_register_option( $wp_customize, array(
				'name'              => 'signify_logo_slider_post_' . $i,
				'sanitize_callback' => 'signify_sanitize_post',
				'active_callback'   => 'signify_is_post_logo_slider_active',
				'input_attrs'       => array(
					'style' => 'width: 80px;',
				),
				'label'             => esc_html__( 'Post', 'signify-pro' ) . ' # ' . $i,
				'section'           => 'signify_logo_slider',
				'choices'           => signify_generate_post_array(),
				'type'              => 'select',
			)
		);

		// Page Sliders
		signify_register_option( $wp_customize, array(
				'name'              => 'signify_logo_slider_page_' . $i,
				'sanitize_callback' => 'signify_sanitize_post',
				'active_callback'   => 'signify_is_page_logo_slider_active',
				'label'             => esc_html__( 'Page', 'signify-pro' ) . ' # ' . $i,
				'section'           => 'signify_logo_slider',
				'type'              => 'dropdown-pages',
			)
		);

		// Image Sliders
		signify_register_option( $wp_customize, array(
				'name'              => 'signify_logo_slider_note_' . $i,
				'sanitize_callback' => 'sanitize_text_field',
				'custom_control'    => 'Signify_Note_Control',
				'active_callback'   => 'signify_is_image_logo_slider_active',
				'label'             => esc_html__( 'Item #', 'signify-pro' ) . $i,
				'section'           => 'signify_logo_slider',
				'type'              => 'description',
			)
		);

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

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

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

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_logo_slider_title_' . $i,
				'sanitize_callback' => 'wp_kses_post',
				'active_callback'   => 'signify_is_image_logo_slider_active',
				'label'             => esc_html__( 'Title', 'signify-pro' ),
				'section'           => 'signify_logo_slider',
				'type'              => 'text',
			)
		);

		signify_register_option( $wp_customize, array(
				'name'              => 'signify_logo_slider_content_' . $i,
				'sanitize_callback' => 'wp_kses_post',
				'active_callback'   => 'signify_is_image_logo_slider_active',
				'label'             => esc_html__( 'Content', 'signify-pro' ),
				'section'           => 'signify_logo_slider',
				'type'              => 'textarea',
			)
		);
	} // End for().
}
add_action( 'customize_register', 'signify_logo_slider_options' );

/** Active Callback Functions */

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

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

if ( ! function_exists( 'signify_is_layout_2_logo_slider_inactive' ) ) :
	/**
	* Return true if layout 2 is not selected
	*
	* @since 1.0.0
	*/
	function signify_is_layout_2_logo_slider_inactive( $control ) {
		$layout = $control->manager->get_setting( 'signify_logo_slider_layout' )->value();

		return ( signify_is_logo_slider_active( $control ) && 'layout-2' !== $layout );
	}
endif;

if ( ! function_exists( 'signify_is_logo_slider_layout_1' ) ) :
	/**
	* Return true layout 1 is selected
	*
	* @since 1.0.0
	*/
	function signify_is_logo_slider_layout_1( $control ) {
		$layout = $control->manager->get_setting( 'signify_logo_slider_layout' )->value();

		//return true only if previwed page on customizer matches the type of logo_slider option selected and is or is not selected type
		return ( signify_is_logo_slider_active( $control ) && 1 === $layout );
	}
endif;


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

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


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

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


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

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

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

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

if ( ! function_exists( 'signify_is_image_logo_slider_inactive' ) ) :
	/**
	* Return true if page logo_slider is inactive
	*
	* @since 1.0.0
	*/
	function signify_is_image_logo_slider_inactive( $control ) {
		$type = $control->manager->get_setting( 'signify_logo_slider_type' )->value();

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