<?php
/**
 * BackButton.
 *
 * @package MadeByAura\Prime\Customizer\Fields\Forms
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Customizer\Fields\Forms;

use MadeByAura\Prime\Customizer\Modules\Add;
use MadeByAura\Prime\Customizer\Modules\Value;
use MadeByAura\Prime\Helpers\SingletonTrait;

defined( 'ABSPATH' ) || die();

/**
 * BackButton.
 */
class BackButton {
	use SingletonTrait;

	/**
	 * Constructor.
	 */
	protected function __construct() {
		add_action( 'after_setup_theme', [ __CLASS__, 'add_section' ] );
	}

	/**
	 * Add section.
	 */
	public static function add_section() {
		$section    = 'form_back_button';
		$css_prefix = '--aura-g-form-button-2';
		$priority   = 10;

		// Section.
		Add::section(
			$section,
			[
				'title'    => esc_attr__( 'Back Button', 'aura-prime' ),
				'section'  => 'aura_section_forms',
				'priority' => 0,
			],
		);

		// Color.
		$id       = 'color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Color', 'aura-prime' ),
				'type'      => 'color',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'choices'   => [
					'alpha' => true,
				],
				'output'    => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-color",
					],
				],
			],
		);

		// Background color.
		$id       = 'background_color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Background color', 'aura-prime' ),
				'type'      => 'color',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'choices'   => [
					'alpha' => true,
				],
				'output'    => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-background-color",
					],
				],
			],
		);

		// Border color.
		$id       = 'border_color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Border color', 'aura-prime' ),
				'type'      => 'color',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'choices'   => [
					'alpha' => true,
				],
				'output'    => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-border-color",
					],
				],
			],
		);

		// Hover color.
		$id       = 'hover_color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Hover color', 'aura-prime' ),
				'type'      => 'color',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'choices'   => [
					'alpha' => true,
				],
				'output'    => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-hover-color",
					],
				],
			],
		);

		// Hover background color.
		$id       = 'hover_background_color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Hover background color', 'aura-prime' ),
				'type'      => 'color',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'choices'   => [
					'alpha' => true,
				],
				'output'    => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-hover-background-color",
					],
				],
			],
		);

		// Hover border color.
		$id       = 'hover_border_color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Hover border color', 'aura-prime' ),
				'type'      => 'color',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'choices'   => [
					'alpha' => true,
				],
				'output'    => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-hover-border-color",
					],
				],
			],
		);

		// Typography.
		$id       = 'typography';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'   => esc_attr__( 'Typography', 'aura-prime' ),
				'type'    => 'typography',
				'default' => Value::get_default( $section, $id ),
				'output'  => [
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => "{$css_prefix}-font-family",
					],
					[
						'choice'   => 'font-size',
						'element'  => ':root',
						'property' => "{$css_prefix}-font-size",
					],
					[
						'choice'   => 'line-height',
						'element'  => ':root',
						'property' => "{$css_prefix}-line-height",
					],
					[
						'choice'   => 'letter-spacing',
						'element'  => ':root',
						'property' => "{$css_prefix}-letter-spacing",
					],
				],
			],
		);

		// Padding.
		$id       = 'padding';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Padding', 'aura-prime' ),
				'type'      => 'dimensions',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'output'    => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-padding",
					],
				],
			],
		);

		// Border width.
		$id       = 'border_width';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'   => esc_attr__( 'Border width', 'aura-prime' ),
				'type'    => 'dimensions',
				'default' => Value::get_default( $section, $id ),
				'choices' => [
					'labels' => [
						'top'    => esc_html__( 'Top', 'aura-prime' ),
						'right'  => esc_html__( 'Right', 'aura-prime' ),
						'bottom' => esc_html__( 'Bottom', 'aura-prime' ),
						'left'   => esc_html__( 'Left', 'aura-prime' ),
					],
				],
				'output'  => [
					[
						'choice'   => 'top',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-top-width",
					],
					[
						'choice'   => 'right',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-right-width",
					],
					[
						'choice'   => 'bottom',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-bottom-width",
					],
					[
						'choice'   => 'left',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-left-width",
					],
				],
			],
		);

		// Border radius.
		$id       = 'border_radius';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Border radius', 'aura-prime' ),
				'type'      => 'dimensions',
				'default'   => Value::get_default( $section, $id ),
				'choices'   => [
					'labels' => [
						'top-left'     => esc_html__( 'Top left', 'aura-prime' ),
						'top-right'    => esc_html__( 'Top right', 'aura-prime' ),
						'bottom-right' => esc_html__( 'Bottom right', 'aura-prime' ),
						'bottom-left'  => esc_html__( 'Bottom left', 'aura-prime' ),
					],
				],
				'transport' => 'auto',
				'output'    => [
					[
						'choice'   => 'top-left',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-top-left-radius",
					],
					[
						'choice'   => 'top-right',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-top-right-radius",
					],
					[
						'choice'   => 'bottom-right',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-bottom-right-radius",
					],
					[
						'choice'   => 'bottom-left',
						'element'  => ':root',
						'property' => "{$css_prefix}-border-bottom-left-radius",
					],
				],
			],
		);

		// Icon location.
		$id       = 'icon_location';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'   => esc_attr__( 'Icon location', 'aura-prime' ),
				'type'    => 'select',
				'default' => Value::get_default( $section, $id ),
				'choices' => [
					'none'        => esc_attr__( 'None', 'aura-prime' ),
					'before_text' => esc_attr__( 'Before text', 'aura-prime' ),
					'after_text'  => esc_attr__( 'After text', 'aura-prime' ),
				],
				'output'  => [
					[
						'choice'        => 'before_text',
						'element'       => '.wsf-button[data-action="wsf-tab_previous"]:before',
						'property'      => 'content',
						'value_pattern' => "''",
						'exclude'       => [ 'none', 'after_text' ],
					],
					[
						'choice'        => 'after_text',
						'element'       => '.wsf-button[data-action="wsf-tab_previous"]:after',
						'property'      => 'content',
						'value_pattern' => "''",
						'exclude'       => [ 'none', 'before_text' ],
					],
					'active_callback' => [
						[
							'setting'  => "aura_{$section}_icon_location",
							'operator' => '!=',
							'value'    => 'none',
						],
					],
				],
			],
		);

		// Icon image.
		$id       = 'icon_image';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'           => esc_attr__( 'Icon image', 'aura-prime' ),
				'type'            => 'image',
				'default'         => Value::get_default( $section, $id ),
				'output'          => [
					[
						'element'       => ':root',
						'property'      => "{$css_prefix}-icon-image",
						'value_pattern' => 'url($)',
					],
				],
				'active_callback' => [
					[
						'setting'  => "aura_{$section}_icon_location",
						'operator' => '!=',
						'value'    => 'none',
					],
				],
			],
		);

		// Icon color.
		$id       = 'icon_color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'           => esc_attr__( 'Icon color', 'aura-prime' ),
				'type'            => 'color',
				'default'         => Value::get_default( $section, $id ),
				'transport'       => 'auto',
				'choices'         => [
					'alpha' => true,
				],
				'output'          => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-icon-color",
					],
				],
				'active_callback' => [
					[
						'setting'  => "aura_{$section}_icon_location",
						'operator' => '!=',
						'value'    => 'none',
					],
				],
			],
		);

		// Icon color: Hover.
		$id       = 'icon_hover_color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'           => esc_attr__( 'Icon color: Hover', 'aura-prime' ),
				'type'            => 'color',
				'default'         => Value::get_default( $section, $id ),
				'transport'       => 'auto',
				'choices'         => [
					'alpha' => true,
				],
				'output'          => [
					[
						'element'  => ':root',
						'property' => "{$css_prefix}-hover-icon-color",
					],
				],
				'active_callback' => [
					[
						'setting'  => "aura_{$section}_icon_location",
						'operator' => '!=',
						'value'    => 'none',
					],
				],
			],
		);

		// Icon size.
		$id       = 'icon_size';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'           => esc_attr__( 'Icon size', 'aura-prime' ),
				'type'            => 'dimensions',
				'default'         => Value::get_default( $section, $id ),
				'transport'       => 'auto',
				'output'          => [
					[
						'choice'   => 'width',
						'element'  => ':root',
						'property' => "{$css_prefix}-icon-width",
					],
					[
						'choice'   => 'height',
						'element'  => ':root',
						'property' => "{$css_prefix}-icon-height",
					],
				],
				'active_callback' => [
					[
						'setting'  => "aura_{$section}_icon_location",
						'operator' => '!=',
						'value'    => 'none',
					],
				],
			],
		);

		// Icon position.
		$id       = 'icon_position';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'           => esc_attr__( 'Icon position', 'aura-prime' ),
				'type'            => 'dimensions',
				'default'         => Value::get_default( $section, $id ),
				'choices'         => [
					'labels' => [
						'gap'    => esc_html__( 'Gap', 'aura-prime' ),
						'offset' => esc_html__( 'Vertical offset', 'aura-prime' ),
					],
				],
				'transport'       => 'auto',
				'output'          => [
					[
						'choice'   => 'gap',
						'element'  => ':root',
						'property' => "{$css_prefix}-icon-gap",
					],
					[
						'choice'   => 'offset',
						'element'  => ':root',
						'property' => "{$css_prefix}-icon-offset",
					],
				],
				'active_callback' => [
					[
						'setting'  => "aura_{$section}_icon_location",
						'operator' => '!=',
						'value'    => 'none',
					],
				],
			],
		);
	}
}
