<?php if( ! defined( 'ABSPATH' ) ) exit;

/**
 * Enqueue scripts and styles.
 */
function faster_animations_scripts() {	
	wp_enqueue_style( 'faster-aos-css', get_template_directory_uri() . '/include/animations/aos.css' );
	wp_enqueue_script( 'faster-aos-js', get_template_directory_uri() . '/include/animations/aos.js', array(), '', true);
	wp_enqueue_script( 'faster-aos-options-js', get_template_directory_uri() . '/include/animations/aos-options.js', array(), '', true);
}
add_action( 'wp_enqueue_scripts', 'faster_animations_scripts' );

/**
 * Default article animation
 */
function  faster_animation ($animation) {
	if ( get_theme_mod( $animation ) != "none" and get_theme_mod( $animation ) != ""  )  {
		return "data-aos-delay='100'"." ".
		"data-aos-duration='500'"." ".
		"data-aos='".esc_html ( get_theme_mod( $animation ) )."'";
	}
	if ( get_theme_mod( $animation  ) == "" ) {
		return "data-aos-delay='100'"." ".
		"data-aos-duration='500'"." ".
		"data-aos='flip-up'";		
	}
}

function faster_animation_calender () {
		return "data-aos-delay='400'"." ".
		"data-aos-duration='500'"." ".
		"data-aos='flip-up'";
}

function faster_animations() {
	$array = array(
				'' => esc_attr__( 'Default', 'faster' ),			
				'none' => esc_attr__( 'Deactivate Animation', 'faster' ),			
				'fade' => esc_attr__( 'fade', 'faster' ),
				'fade-up' => esc_attr__( 'fade-up', 'faster' ),
				'fade-down' => esc_attr__( 'fade-down', 'faster' ),
				'fade-left' => esc_attr__( 'fade-left', 'faster' ),
				'fade-right' => esc_attr__( 'fade-right', 'faster' ),
				'fade-up-right' => esc_attr__( 'fade-up-right', 'faster' ),
				'fade-up-left' => esc_attr__( 'fade-up-left', 'faster' ),
				'fade-down-right' => esc_attr__( 'fade-down-right', 'faster' ),
				'fade-down-left' => esc_attr__( 'fade-down-left', 'faster' ),
				'flip-up' => esc_attr__( 'flip-up', 'faster' ),
				'flip-down' => esc_attr__( 'flip-down', 'faster' ),
				'flip-left' => esc_attr__( 'flip-left', 'faster' ),
				'flip-right' => esc_attr__( 'flip-right', 'faster' ),
				'slide-up' => esc_attr__( 'slide-up', 'faster' ),
				'slide-down' => esc_attr__( 'slide-down', 'faster' ),
				'slide-left' => esc_attr__( 'slide-left', 'faster' ),
				'slide-right' => esc_attr__( 'slide-right', 'faster' ),
				'zoom-in' => esc_attr__( 'zoom-in', 'faster' ),
				'zoom-in-up' => esc_attr__( 'zoom-in-up', 'faster' ),
				'zoom-in-down' => esc_attr__( 'zoom-in-down', 'faster' ),
				'zoom-in-left' => esc_attr__( 'zoom-in-left', 'faster' ),
				'zoom-in-right' => esc_attr__( 'zoom-in-right', 'faster' ),
				'zoom-out' => esc_attr__( 'zoom-out', 'faster' ),
				'zoom-out-up' => esc_attr__( 'zoom-out-up', 'faster' ),
				'zoom-out-down' => esc_attr__( 'zoom-out-down', 'faster' ),
				'zoom-out-left' => esc_attr__( 'zoom-out-left', 'faster' ),
				'zoom-out-right' => esc_attr__( 'zoom-out-right', 'faster' ),
				);
	return $array;
}


		function faster_sanitize_animations( $input ) {

			$valid = faster_animations();

			if ( array_key_exists( $input, $valid ) ) {
				return $input;
			} else {
				return '';
			}
		}
		
function faster_animations_customize_register( $wp_customize ) {
 
		$wp_customize->add_panel( 'faster_panel_animations' , array(
			'title'       => __( 'Animations', 'faster' ),
			'priority'   => 7,
		) );

/************************************
* Animation Articles
************************************/

		$wp_customize->add_section( 'faster_animations_section_articles' , array(
			'title'       => __( 'Animation Articles', 'faster' ),
			'panel'       => 'faster_panel_animations',
			'priority'   => 64,
		) );
		
		$wp_customize->add_setting( 'faster_articles_animation', array (
			'sanitize_callback' => 'faster_sanitize_animations',
		) );
		
		$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'faster_articles_animation', array(
			'label'    => __( 'Animation Articles', 'faster' ),
			'description'       => __( 'Animations of all elements - PRO version of the theme.', 'faster' ),
			'section'  => 'faster_animations_section_articles',
			'settings' => 'faster_articles_animation',
			'type'     =>  'select',
            'choices'  => faster_animations(),		
		) ) );

/************************************
* Animation Header Buttons
************************************/

		$wp_customize->add_section( 'faster_animations_section_buttons' , array(
			'title'       => __( 'Animation Header Buttons', 'faster' ),
			'panel'       => 'faster_panel_animations',
			'priority'   => 64,
		) );
		
		$wp_customize->add_setting( 'faster_button_1_animation', array (
			'sanitize_callback' => 'faster_sanitize_animations',
		) );
		
		$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'faster_button_1_animation', array(
			'label'    => __( 'Button 1', 'faster' ),
			'section'  => 'faster_animations_section_buttons',
			'settings' => 'faster_button_1_animation',
			'type'     =>  'select',
            'choices'  => faster_animations(),		
		) ) );
		
		
		$wp_customize->add_setting( 'faster_button_2_animation', array (
			'sanitize_callback' => 'faster_sanitize_animations',
		) );
		
		$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'faster_button_2_animation', array(
			'label'    => __( 'Button 2', 'faster' ),
			'section'  => 'faster_animations_section_buttons',
			'settings' => 'faster_button_2_animation',
			'type'     =>  'select',
            'choices'  => faster_animations(),		
		) ) );
				
}
add_action( 'customize_register', 'faster_animations_customize_register' );
