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

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

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

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

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

		// Color.
		$id       = 'accent_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-checkbox-accent-color',
					],
				],
			],
		);

		// Size.
		$id       = 'size';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Size', 'aura-prime' ),
				'type'      => 'dimensions',
				'default'   => Value::get_default( $section, $id ),
				'choices'   => [
					'labels' => [
						'width'    => esc_html__( 'Width', 'aura-prime' ),
						'offset_y' => esc_html__( 'Offset Y', 'aura-prime' ),
					],
				],
				'transport' => 'auto',
				'output'    => [
					[
						'choice'   => 'width',
						'element'  => ':root',
						'property' => '--aura-g-checkbox-size',
					],
					[
						'choice'   => 'offset_y',
						'element'  => ':root',
						'property' => '--aura-g-checkbox-offset-y',
					],
				],
			],
		);

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

		// Group gap.
		$id       = 'group_gap';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'     => esc_attr__( 'Group gap', 'aura-prime' ),
				'type'      => 'dimensions',
				'default'   => Value::get_default( $section, $id ),
				'choices'   => [
					'labels' => [
						'column' => esc_html__( 'Column', 'aura-prime' ),
						'row'    => esc_html__( 'Row', 'aura-prime' ),
					],
				],
				'transport' => 'auto',
				'output'    => [
					[
						'choice'   => 'column',
						'element'  => ':root',
						'property' => '--aura-g-checkbox-group-gap-x',
					],
					[
						'choice'   => 'row',
						'element'  => ':root',
						'property' => '--aura-g-checkbox-group-gap-y',
					],
				],
			],
		);
	}
}
