<?php
/**
 * Legend.
 *
 * @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();

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

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

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

		// Section.
		Add::section(
			$section,
			[
				'title'    => esc_attr__( 'Legend', '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' => '--aura-g-legend-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' => '--aura-g-legend-font-family',
					],
					[
						'choice'   => 'font-size',
						'element'  => ':root',
						'property' => '--aura-g-legend-font-size',
					],
					[
						'choice'   => 'line-height',
						'element'  => ':root',
						'property' => '--aura-g-legend-line-height',
					],
					[
						'choice'   => 'letter-spacing',
						'element'  => ':root',
						'property' => '--aura-g-legend-letter-spacing',
					],
				],
			],
		);

		// Gap between legend and fields.
		$id       = 'fields_gap';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Gap between legend and fields', 'aura-prime' ),
				'type'      => 'dimension',
				'default'   => Value::get_default( $section, $id ),
				'transport' => 'auto',
				'output'    => [
					[
						'element'  => ':root',
						'property' => '--aura-g-legend-fields-gap',
					],
				],
			],
		);
	}
}
