<?php
/**
 * Admin asset loading context helpers.
 *
 * @package WP_PowerSuite\Core
 * @since 1.0.0
 */

namespace WP_PowerSuite\Core;

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

/**
 * Determines when module admin assets should enqueue.
 */
final class AdminAssetContext {

	/**
	 * Whether scripts/styles for wp-admin UI should load on the current request.
	 *
	 * @param string $hook Current admin page hook suffix.
	 */
	public static function shouldLoadAssets( string $hook = '' ): bool {
		if ( wp_doing_ajax() || wp_doing_cron() ) {
			return false;
		}

		if ( $hook === 'wp-login.php' ) {
			return false;
		}

		/**
		 * Filter whether a module may load admin assets on the current screen.
		 *
		 * @since 1.0.0
		 * @param bool   $should_load Default true when not AJAX/cron/login.
		 * @param string $hook        Admin page hook suffix.
		 */
		return (bool) apply_filters( 'wp_powersuite_admin_should_load_assets', true, $hook );
	}
}
