<?php
/**
 * Scripts.
 *
 * @package MadeByAura\Prime\Customizer\Hooks
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Customizer\Hooks;

use MadeByAura\Prime\Helpers\SingletonTrait;

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

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

	/**
	 * Constructor.
	 */
	protected function __construct() {
		add_action( 'customize_controls_print_styles', [ __CLASS__, 'add_embedded_css' ], 99910 );

		// Add embedded css specific to Kirki versions.
		if ( version_compare( \KIRKI_VERSION, '3.1.9', '>' ) ) {
			add_action( 'customize_controls_print_styles', [ __CLASS__, 'add_v4_embedded_css' ], 99920 );
		} else {
			add_action( 'customize_controls_print_styles', [ __CLASS__, 'add_v3_embedded_css' ], 99920 );
		}
	}

	/**
	 * Add embedded css.
	 */
	public static function add_embedded_css() {
		?>
		<style>
			/* -----------------------------------------------------------------------
			 * Nested section.
			 * -------------------------------------------------------------------- */
			#customize-theme-controls .control-section.open .control-section-kirki-nested .accordion-section-title {
				background: #fff;
				border-left-color: #fff;
				color: #555d66;
			}

			#customize-theme-controls .control-section.open .control-section-kirki-nested .accordion-section-title::after {
				color: #a0a5aa;
			}

			#customize-theme-controls .control-section.open .control-section-kirki-nested .accordion-section-title::after:hover {
				background: #f3f3f5;
				border-left-color: #0073aa;
				color: #0073aa;
			}

			#customize-theme-controls .control-section.open .control-section-kirki-nested .accordion-section-title::after:hover::after {
				color: #0073aa;
			}

			/* -----------------------------------------------------------------------
			 * Spacer section.
			 * -------------------------------------------------------------------- */
			.control-section-kirki-spacer {
				background-color: #eee;
				border-bottom: 1px solid #ddd;
				height: 10px;
				pointer-events: none;
			}

			.control-section-kirki-spacer .accordion-section-title {
				display: none;
			}
		</style>
		<?php
	}

	/**
	 * Add embedded css specific to Kirki v4.
	 */
	public static function add_v4_embedded_css() {
		?>
		<style>
			/* -----------------------------------------------------------------------
			 * Dimension control.
			 * -------------------------------------------------------------------- */
			.customize-control-kirki-dimension .has-label-bottom .kirki-control-label {
				font-size: 10px;
				line-height: 1.1;
			}
		</style>
		<?php
	}

	/**
	 * Add embedded css specific to Kirki v3.
	 */
	public static function add_v3_embedded_css() {
		?>
		<style>
			/* -----------------------------------------------------------------------
			* Typography control.
			* -------------------------------------------------------------------- */
			.customize-control-kirki-typography .wrapper {
				padding-top: 0;
			}

			/* -----------------------------------------------------------------------
			 * Dimensions control.
			 * -------------------------------------------------------------------- */
			.customize-control-kirki-dimensions .wrapper .control {
				flex-wrap: nowrap;
				gap: 5px;
			}

			.customize-control-kirki-dimensions .wrapper .control > div {
				display: flex;
				flex-direction: column;
				width: 100%;
			}

			.customize-control-kirki-dimensions .wrapper .control > div h5 {
				margin: 3px 0 0;
				order: 2;
				text-align: center;
			}
		</style>
		<?php
	}
}
