<?php
/**
 * Backwards-compatible AdminPageHeader adapter
 *
 * This file provides the methods expected by the old enforce_manage_*.php
 * modules but delegates to the new PermissionEnforcer / SubAdminPageGuard
 * implementations so legacy calls actually enforce permissions.
 */

require_once __DIR__ . '/permission_enforcer.php';
require_once __DIR__ . '/subadmin_page_guard.php';

class AdminPageHeader {

	/**
	 * Require page access for a feature. Mirrors old API used by
	 * EnforceManageX::guardPage() calls.
	 * @param string $feature
	 */
	public static function requirePage($feature) {
		// Delegate to PermissionEnforcer which handles admin/subadmin/login flows
		return PermissionEnforcer::guardPage($feature);
	}

	/**
	 * Require action access for a feature (create/edit/delete/view)
	 * Mirrors old API used by EnforceManageX::guardAction()
	 * @param string $feature
	 * @param string $action
	 */
	public static function requireAction($feature, $action) {
		return PermissionEnforcer::guardAction($feature, $action);
	}

	/**
	 * Return a guard object compatible with older modules. We return
	 * an instance of SubAdminPageGuard which provides getCapabilities(),
	 * can(), isAdmin(), isSubadmin(), etc.
	 * @param string $feature
	 * @return SubAdminPageGuard
	 */
	public static function getGuard($feature) {
		return new SubAdminPageGuard($feature);
	}

	/**
	 * Convenience wrapper for capability checking
	 * @param string $feature
	 * @param string $action
	 * @return bool
	 */
	public static function can($feature, $action) {
		$guard = self::getGuard($feature);
		return $guard->can($action);
	}
}

?>
