<?php
/**
 * Customizer settings: preloaders (page transition)
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}

/**
 * Customizer settings for preloader (page transition)
 */
class Multimagazine_Customize_Preloader {

	/**
	 * Registers the section and fires the extension hook.
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer manager instance.
	 */
	public static function register_section( $wp_customize ) {
		$wp_customize->add_section(
			'preloader',
			array(
				'title'    => __( 'Preloader', 'multimagazine' ),
				'priority' => 60,
			)
		);
		do_action( 'multimagazine_customize_preloader', $wp_customize );
	}

	/**
	 * Registers the preloader setting.
	 */
	public static function register_preloader() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_preloader', 'preloader', __( 'Show preloader while pages (re)load', 'multimagazine' ) );
	}

	/**
	 * Registers the preloader loading only setting.
	 */
	public static function register_preloader_loading_only() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_preloader_loading_only', 'preloader', __( 'Show preloader only while page loads (don\'t show on page unload)', 'multimagazine' ) );
	}

	/**
	 * Registers the animation setting.
	 */
	public static function register_animation() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_preloader_animation',
			'preloader',
			array(
				'bg-fade'            => __( 'Background fade', 'multimagazine' ),
				'bg-grow-l'          => __( 'Background grow from left', 'multimagazine' ),
				'bg-grow-l2'         => __( 'Background grow from left 2', 'multimagazine' ),
				'bg-grow-lr'         => __( 'Background grow from left and right', 'multimagazine' ),
				'bg-grow-m'          => __( 'Background grow from middle', 'multimagazine' ),
				'bg-grow-m-circle'   => __( 'Background grow from middle circle', 'multimagazine' ),
				'bg-grow-m-circle2'  => __( 'Background grow from middle circle 2', 'multimagazine' ),
				'bg-grow-top'        => __( 'Background grow from top', 'multimagazine' ),
				'bg-grow-bottom'     => __( 'Background grow from bottom', 'multimagazine' ),
				'bg-grow-bottom2'    => __( 'Background grow from bottom 2', 'multimagazine' ),
				'bg-grow-top-bottom' => __( 'Background grow from top and bottom', 'multimagazine' ),
				'none'               => __( 'None', 'multimagazine' ),
			),
			__( 'Preloader showing and hiding animation', 'multimagazine' )
		);
	}

	/**
	 * Registers the bg color setting.
	 */
	public static function register_bg_color() {
		global $multimagazine_customize;
		$multimagazine_customize->color_setting( 'multi_preloader_bg_color', 'preloader', __( 'Background color', 'multimagazine' ) );
	}

	/**
	 * Registers the spinner type setting.
	 */
	public static function register_spinner_type() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_preloader_spinner_type',
			'preloader',
			array(
				''        => __( 'None', 'multimagazine' ),
				'spinner' => __( 'Spinner', 'multimagazine' ),
				'media'   => __( 'Image/video', 'multimagazine' ),
				'lottie'  => __( 'Lottie', 'multimagazine' ),
			),
			__( 'Spinner type', 'multimagazine' )
		);
	}

	/**
	 * Registers the spinner setting.
	 */
	public static function register_spinner() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_preloader_spinner',
			'preloader',
			array(
				1 => __( 'Style 1', 'multimagazine' ),
				2 => __( 'Style 2', 'multimagazine' ),
				3 => __( 'Style 3', 'multimagazine' ),
				4 => __( 'Style 4', 'multimagazine' ),
				5 => __( 'Style 5', 'multimagazine' ),
			),
			__( 'Spinner', 'multimagazine' )
		);
	}

	/**
	 * Registers the spinner color setting.
	 */
	public static function register_spinner_color() {
		global $multimagazine_customize;
		$multimagazine_customize->color_setting( 'multi_preloader_spinner_color', 'preloader', __( 'Spinner color', 'multimagazine' ) );
	}

	/**
	 * Registers the media setting.
	 */
	public static function register_media() {
		global $multimagazine_customize;
		$multimagazine_customize->image_setting( 'multi_preloader_media', 'preloader', __( 'Preloader media', 'multimagazine' ), '' );
	}

	/**
	 * Registers the media width setting.
	 */
	public static function register_media_width() {
		global $multimagazine_customize;
		$multimagazine_customize->number_setting( 'multi_preloader_media_width', 'preloader', __( 'Media width', 'multimagazine' ) );
	}

	/**
	 * Registers the media height setting.
	 */
	public static function register_media_height() {
		global $multimagazine_customize;
		$multimagazine_customize->number_setting( 'multi_preloader_media_height', 'preloader', __( 'Media height', 'multimagazine' ) );
	}

	/**
	 * Adds the lottie heading.
	 */
	public static function register_lottie_heading() {
		multimagazine_add_heading( 'multi_lottie_title', 'preloader', __( 'Lottie', 'multimagazine' ) );
	}

	/**
	 * Registers the lottie file setting.
	 */
	public static function register_lottie_file() {
		global $multimagazine_customize;
		$multimagazine_customize->media_setting(
			'multi_preloader_lottie_file',
			'preloader',
			__( 'Lottie file', 'multimagazine' ),
			'',
			array( 'Multimagazine_Sanitizer', 'number_int' )
		);
	}

	/**
	 * Registers the lottie url setting.
	 */
	public static function register_lottie_url() {
		global $multimagazine_customize;
		$multimagazine_customize->text_setting( 'multi_preloader_lottie_url', 'preloader', __( 'Lottie file URL', 'multimagazine' ), __( 'Used only if no file is chosen in the field above', 'multimagazine' ) );
	}

	/**
	 * Registers the lottie mode setting.
	 */
	public static function register_lottie_mode() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_preloader_lottie_mode',
			'preloader',
			array(
				''       => __( 'Normal', 'multimagazine' ),
				'bounce' => __( 'Bounce', 'multimagazine' ),
			),
			__( 'Lottie play mode', 'multimagazine' )
		);
	}

	/**
	 * Registers the lottie speed setting.
	 */
	public static function register_lottie_speed() {
		global $multimagazine_customize;
		$multimagazine_customize->number_setting( 'multi_preloader_lottie_speed', 'preloader', __( 'Lottie animation speed', 'multimagazine' ), __( 'Default speed: 1, Faster: > 1, Slower: between 0 and 1', 'multimagazine' ) );
	}

	/**
	 * Registers the lottie width setting.
	 */
	public static function register_lottie_width() {
		global $multimagazine_customize;
		$multimagazine_customize->text_setting( 'multi_preloader_lottie_width', 'preloader', __( 'Lottie width', 'multimagazine' ), __( 'Any CSS-compatible width value', 'multimagazine' ) );
	}

	/**
	 * Registers the lottie height setting.
	 */
	public static function register_lottie_height() {
		global $multimagazine_customize;
		$multimagazine_customize->text_setting( 'multi_preloader_lottie_height', 'preloader', __( 'Lottie height', 'multimagazine' ), __( 'Any CSS-compatible height value', 'multimagazine' ) );
	}
}

add_action( 'customize_register', array( 'Multimagazine_Customize_Preloader', 'register_section' ) );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_preloader' ), 10 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_preloader_loading_only' ), 15 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_animation' ), 20 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_bg_color' ), 25 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_spinner_type' ), 30 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_spinner' ), 35 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_spinner_color' ), 40 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_media' ), 45 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_media_width' ), 50 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_media_height' ), 55 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_lottie_heading' ), 60 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_lottie_file' ), 65 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_lottie_url' ), 70 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_lottie_mode' ), 75 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_lottie_speed' ), 80 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_lottie_width' ), 85 );
add_action( 'multimagazine_customize_preloader', array( 'Multimagazine_Customize_Preloader', 'register_lottie_height' ), 90 );
