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

namespace MadeByAura\Prime\Customizer\Fields;

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

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

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

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

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

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

		// Body.
		$id       = 'body';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'   => esc_attr__( 'Body', 'aura-prime' ),
				'type'    => 'typography',
				'default' => Value::get_default( $section, $id ),
				'choices' => [
					'variant' => [
						'regular',
						'italic',
						'700',
						'700italic',
					],
				],
				'output'  => [
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => '--aura-g-body-font-family',
					],
					[
						'choice'   => 'font-size',
						'element'  => ':root',
						'property' => '--aura-g-body-font-size',
					],
					[
						'choice'   => 'line-height',
						'element'  => ':root',
						'property' => '--aura-g-body-line-height',
					],
					[
						'choice'   => 'letter-spacing',
						'element'  => ':root',
						'property' => '--aura-g-body-letter-spacing',
					],
				],
			],
		);

		// Headings.
		$id       = 'headings';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'   => esc_attr__( 'Headings', 'aura-prime' ),
				'type'    => 'typography',
				'default' => Value::get_default( $section, $id ),
				'choices' => [
					'variant' => [
						'regular',
						'italic',
						'700',
						'700italic',
					],
				],
				'output'  => [
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => '--aura-g-h1-font-family',
					],
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => '--aura-g-h2-font-family',
					],
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => '--aura-g-h3-font-family',
					],
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => '--aura-g-h4-font-family',
					],
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => '--aura-g-h5-font-family',
					],
					[
						'choice'   => 'font-family',
						'element'  => ':root',
						'property' => '--aura-g-h6-font-family',
					],
				],
			],
		);
	}
}
