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

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

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

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

		// Section.
		Add::section(
			$section,
			[
				'title'    => esc_attr__( 'Image caption', '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(figcaption)',
						'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(figcaption)',
						'property' => 'background-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'  => '.aura-formatted-content :where(figcaption)',
						'property' => 'font-family',
					],
					[
						'choice'   => 'font-size',
						'element'  => '.aura-formatted-content :where(figcaption)',
						'property' => 'font-size',
					],
					[
						'choice'   => 'line-height',
						'element'  => '.aura-formatted-content :where(figcaption)',
						'property' => 'line-height',
					],
					[
						'choice'   => 'letter-spacing',
						'element'  => '.aura-formatted-content :where(figcaption)',
						'property' => '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'  => '.aura-formatted-content :where(figcaption)',
						'property' => 'padding',
					],
				],
			],
		);
	}
}
