<?php

namespace WPSN\Core;

defined('ABSPATH') || exit;

/**
 * UI mode helpers.
 *
 * NOTE: This is intentionally NOT related to licensing.
 * It only affects how much UI is shown (Simple vs Pro).
 */
final class UI
{
    public const MODE_SIMPLE = 'simple';
    public const MODE_PRO = 'pro';

    public static function mode(Settings $settings): string
    {
        // Default to the full (Pro) UI.
        //
        // We can still provide a Simple UI as an optional convenience layer, but
        // the project roadmap requires the full toolset to be visible by default.
        $mode = sanitize_key((string) $settings->get('ui.mode', self::MODE_PRO));
        if ($mode !== self::MODE_PRO) {
            $mode = self::MODE_SIMPLE;
        }

        /**
         * Filter UI mode.
         *
         * @param string   $mode     simple|pro
         * @param Settings $settings Settings object
         */
        $mode = (string) apply_filters('wpsn/ui/mode', $mode, $settings);
        return $mode === self::MODE_PRO ? self::MODE_PRO : self::MODE_SIMPLE;
    }

    public static function isPro(Settings $settings): bool
    {
        return self::mode($settings) === self::MODE_PRO;
    }

    public static function isSimple(Settings $settings): bool
    {
        return !self::isPro($settings);
    }

    /**
     * Tools pages (Tools → …) that should be hidden from the menu in Simple mode.
     *
     * IMPORTANT: pages are still registered, just removed from the menu.
     * This avoids breaking direct links and preserves functionality.
     *
     * @return string[]
     */
    public static function proOnlyToolsPages(): array
    {
        return [
            // Advanced helpers / dev UX.
            'wpsn-tokens-variables',

            // Emergency/rollback tooling (keep available, but hide in Simple by default).
            'wpsn-undo',

            // Data + intelligence.
            'wpsn-search-console',
            'wpsn-serp-gap',
            'wpsn-drift-monitor',
            'wpsn-indexation-risk',
            'wpsn-analysis-report',
            'wpsn-activity-log',

            // Bulk / automation.
            'wpsn-bulk',
            'wpsn-bulk-table',

            // Advanced operational tooling.
            'wpsn-config-sync',
            'wpsn-revisions',
            'wpsn-queue',
            'wpsn-redirect-migration',
            'wpsn-seo-media',
            'wpsn-schema-validator',
            'wpsn-url-rules',

            // Developer QA (keep available, but hide in Simple by default).
            'wpsn-quality-gate',

            // Optional integrations.
            'wpsn-indexnow',
            'wpsn-ai-readiness',
            'wpsn-privacy',
            'wpsn-setup-wizard',

            // SaaS / licensing (still plugin core, but advanced).
            'wpsn-license',
            'wpsn-saas-sync',

            // Enterprise/unique feature modules.
            'wpsn-auto-pilot',
            'wpsn-content-clusters',
            'wpsn-crawl-budget',
            'wpsn-site-crawl',
        ];
    }

    /**
     * Module IDs that should be hidden from the Modules list in Simple mode.
     *
     * @return string[]
     */
    public static function proOnlyModules(): array
    {
        return [
            'woocommerce',
            'local_seo',
            'author_seo',
            'analysis',
            'page_builders',
            'custom_fields',
            'multisite',
            'import_export',
            'config_sync',
            'indexnow',
            'bulk',
            'bulk_table',
            'media',
            'ai_readiness',
            'ai',
            'automation',
            'search_console',
            'autopilot',
            'content_clusters',
            'crawl_budget',
            'site_crawl',
            'schema_validator',
            'activity_log',
            'onboarding',
            'drift_monitor',
            'indexation_risk',
            'licensing',
            'saas_sync',
            'serp_gap',
        ];
    }
}
