<?php
/**
 * Settings page CSS enqueuing.
 *
 * @package PDFDraft_WooCommerce
 */

namespace PDFDraft\Woocommerce\Admin\Settings;

use PDFDraft\Traits\Hooks;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Enqueues the compiled Tailwind CSS bundle for the WooCommerce PDF settings page.
 *
 * Keeping this separate from {@see \PDFDraft\Woocommerce\Core\Assets} means the
 * settings CSS concern lives next to the rest of the settings infrastructure and
 * does not clutter the main asset class.
 */
class PageAssets {

	use Hooks;

	/**
	 * Register WordPress hooks.
	 *
	 * WooCommerce settings CSS is now loaded on the unified PDFDraft settings page
	 * via the `pdfdraft_settings_page_enqueue_scripts` action (fired only when that
	 * page is active), replacing the previous per-plugin screen detection.
	 *
	 * @return void
	 */
	public function initHooks(): void {
		$this->addAction( 'pdfdraft_settings_page_enqueue_scripts', array( $this, 'enqueueStyles' ) );
	}

	/**
	 * Enqueue the WooCommerce settings CSS on the unified PDFDraft settings page.
	 *
	 * Called via `pdfdraft_settings_page_enqueue_scripts` — no page detection needed.
	 *
	 * @return void
	 */
	public function enqueueStyles(): void {
		if ( ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$css_path = PDFDRAFT_PDF_INVOICES_FOR_WOOCOMMERCE_PLUGIN_DIR . '/dist/woocommerce-settings.css';

		if ( ! file_exists( $css_path ) ) {
			return;
		}

		wp_enqueue_style(
			'pdfdraft-woocommerce-settings',
			untrailingslashit( PDFDRAFT_PDF_INVOICES_FOR_WOOCOMMERCE_PLUGIN_URL ) . '/dist/woocommerce-settings.css',
			array( 'pdfdraft-editor' ),
			(string) filemtime( $css_path )
		);
	}
}
