<?php
/**
 * Blockquote.
 *
 * @package MadeByAura\Prime\Customizer\Fields\Content
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Customizer\Fields\Content;

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

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

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

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

	/**
	 * Add section.
	 */
	public static function add_section() {
		$section  = 'content_blockquote';
		$priority = 10;

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

		// Text color.
		$id       = 'color';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Text color', 'aura-prime' ),
				'type'      => 'color',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'choices'   => [
					'alpha' => true,
				],
				'output'    => [
					[
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => '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'  => '.aura-formatted-content :where(blockquote)',
						'property' => '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'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-color',
					],
				],
			],
		);

		// Padding.
		$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'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'font-family',
					],
					[
						'choice'   => 'font-size',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'font-size',
					],
					[
						'choice'   => 'line-height',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'line-height',
					],
					[
						'choice'   => 'letter-spacing',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'letter-spacing',
					],
				],
			],
		);

		// Enable ACF menu item.
		$id       = 'force_italic';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'       => esc_attr__( 'Force Italic', 'aura-prime' ),
				'description' => esc_attr__( 'Some fonts don\'t have an italic version. You can force it with this option.', 'aura-prime' ),
				'type'        => 'checkbox',
				'default'     => Value::get_default( $section, $id ),
			],
		);

		// 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'  => '.aura-formatted-content :where(blockquote)',
						'property' => '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'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-top-width',
					],
					[
						'choice'   => 'right',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-right-width',
					],
					[
						'choice'   => 'bottom',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-bottom-width',
					],
					[
						'choice'   => 'left',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-left-width',
					],
				],
			],
		);

		// Border style.
		// The theme CSS has the border only on the left side. We need to add
		// `border-style: solid`, to make sure that border_width field can change
		// borders of all sides.
		$id       = 'border_width_style';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'type'    => 'hidden',
				'default' => 'solid',
				'output'  => [
					[
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-style',
					],
				],
			],
		);

		// 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' ),
					],
				],
				'output'  => [
					[
						'choice'   => 'top-left',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-top-left-radius',
					],
					[
						'choice'   => 'top-right',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-top-right-radius',
					],
					[
						'choice'   => 'bottom-right',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-bottom-right-radius',
					],
					[
						'choice'   => 'bottom-left',
						'element'  => '.aura-formatted-content :where(blockquote)',
						'property' => 'border-bottom-left-radius',
					],
				],
			],
		);
	}
}
