<?php
/**
 * Shared field/inspector UI stylesheet (admin + Gutenberg + frontend editor).
 *
 * @package JOCBM
 */

namespace JOCBM\Assets;

defined( 'ABSPATH' ) || exit;

/**
 * Registers and enqueues build/shared-ui.css.
 */
final class SharedUi {

	public const STYLE_HANDLE = 'joc-blockora-morph-shared-ui';

	/**
	 * Register the shared UI stylesheet (idempotent).
	 */
	public static function register(): void {
		if ( wp_style_is( self::STYLE_HANDLE, 'registered' ) ) {
			return;
		}

		$css_path = JOCBM_PATH . 'build/shared-ui.css';
		if ( ! is_readable( $css_path ) ) {
			return;
		}

		wp_register_style(
			self::STYLE_HANDLE,
			JOCBM_URL . 'build/shared-ui.css',
			array( 'wp-components' ),
			JOCBM_VERSION . '.' . (string) filemtime( $css_path )
		);
	}

	/**
	 * Enqueue the shared UI stylesheet.
	 */
	public static function enqueue(): void {
		self::register();
		if ( wp_style_is( self::STYLE_HANDLE, 'registered' ) ) {
			wp_enqueue_style( self::STYLE_HANDLE );
		}
	}
}
