<?php

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound -- APD is the established namespace shared with the Pro add-on and retained for backward compatibility.
namespace APD\Admin;

defined('ABSPATH') || exit;

final class AdminAccess
{
    public static function canUse(string $feature) : bool
    {
        $feature = sanitize_key($feature);
        if ($feature === '') {
            return false;
        }

        $overview = AdminOverview::snapshot();
        return ! empty($overview['license']['active'])
            && ! empty($overview['license']['features'][$feature]);
    }

    public static function renderUnavailable(string $title, string $description) : void
    {
        $overview = AdminOverview::snapshot();
        $theme = sanitize_html_class((string) ($overview['settings']['admin_theme'] ?? 'light'));

        echo '<div class="wrap apd-admin-shell apd-admin-theme-' . esc_attr($theme) . '">';
        echo '<div class="apd-page-heading">';
        echo '<span class="apd-badge">' . esc_html__('Premium module', 'asuka-product-designer') . '</span>';
        echo '<h1>' . esc_html($title) . '</h1>';
        echo '<p>' . esc_html($description) . '</p>';
        echo '</div>';
        echo '<section class="apd-dashboard-card apd-feature-locked">';
        echo '<span class="dashicons dashicons-lock" aria-hidden="true"></span>';
        echo '<div>';
        echo '<h2>' . esc_html__('This module is not available for the active license', 'asuka-product-designer') . '</h2>';
        echo '<p>' . esc_html__('Connect an eligible license or refresh the current license status before opening this workspace.', 'asuka-product-designer') . '</p>';
        echo '<a class="button button-primary" href="' . esc_url(admin_url('admin.php?page=apd-settings')) . '">' . esc_html__('Review license settings', 'asuka-product-designer') . '</a>';
        echo '</div>';
        echo '</section>';
        echo '</div>';
    }
}
