<?php
/**
 * Handles style assets.
 *
 * @package northmill-online-shared
 *
 * @phpcs:disable Squiz.Commenting.FunctionComment.MissingParamTag
 */

declare(strict_types=1);

namespace Northmill_Online_Shared\Modules\Assets\Models;

defined( 'ABSPATH' ) || exit;

/**
 * Class Style_Asset_Model
 */
class Style_Asset_Model extends Abstract_Asset_Model {

	/**
	 * {@inheritDoc}
	 */
	protected function maybe_enqueue_asset( bool $is_shared, string $path_base, string $url_base ): void {
		$asset = $this->get_asset(
			$path_base,
			$url_base,
			'css'
		);

		if ( $asset ) {
			$handle = $this->build_handle( 'style', $is_shared );

			if ( $this->is_dependency ) {
				wp_register_style(
					$handle,
					$asset['url'],
					$this->asset_dependencies,
					filemtime( $asset['path'] )
				);
			} else {
				wp_enqueue_style(
					$handle,
					$asset['url'],
					$this->asset_dependencies,
					filemtime( $asset['path'] )
				);
			}
		}
	}
}
