<?php

namespace UltraguardPro\modules\upgrade_manager\pages;

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

class UpgradeManagerDashboard extends UpgradeManagerPage {

    public function get_scheme( $context ): array {
        unset( $context );

        $status           = $this->license_status();
        $feature_sections = $this->build_feature_sections( $status );

        return [
            'type'      => 'page',
            'id'        => 'ultraguard-upgrade-manager-dashboard',
            'page_slug' => 'upgrade-manager',
            'header'    => [
                'title'    => __( 'Unlock the full UltraGuard security stack', 'ultraguard-security-suite' ),
                'subtitle' => __( 'Compare Free vs Pro vs Agency and see exactly which premium scanning, monitoring, intelligence, reporting, and response capabilities unlock at each tier.', 'ultraguard-security-suite' ),
                'badge'    => $this->status_badge( $status ),
                'actions'  => [
                    $this->create_url_button( __( 'License Activation', 'ultraguard-security-suite' ), $this->get_page_url( 'upgrade-manager-free' ), 'secondary', 'dashicons-unlock' ),
                    $this->create_url_button( __( 'Entitlements', 'ultraguard-security-suite' ), $this->get_page_url( 'upgrade-manager-paid' ), 'secondary', 'dashicons-admin-network' ),
                    $this->create_ajax_button( __( 'Refresh License Status', 'ultraguard-security-suite' ), 'ultraguard_upgrade_manager_refresh_status', [], 'primary', 'dashicons-update' ),
                ],
            ],
            'data'      => array_merge(
                [
                    [
                        'type'       => 'alert-box',
                        'alert_type' => $status['is_pro'] ? 'success' : 'info',
                        'title'      => $status['is_pro']
                            ? __( 'Your premium entitlement is live on this site', 'ultraguard-security-suite' )
                            : __( 'Everything below is what a paid UltraGuard rollout adds', 'ultraguard-security-suite' ),
                        'message'    => $status['is_pro']
                            ? __( 'Use this page as a complete entitlement map for what your paid plan unlocks today and what Agency adds when you need broader coverage across managed sites.', 'ultraguard-security-suite' )
                            : __( 'This dashboard is intentionally detailed so you can understand the operational value behind each premium protection module before you upgrade.', 'ultraguard-security-suite' ),
                    ],
                    [
                        'type'    => 'grid',
                        'columns' => 12,
                        'gap'     => '16px',
                        'items'   => $this->build_plan_cards( $status ),
                    ],
                    [
                        'type'    => 'grid',
                        'columns' => 12,
                        'gap'     => '20px',
                        'items'   => [
                            [
                                'span'       => 5,
                                'responsive' => [ 'lg' => 12 ],
                                'component'  => $this->build_status_card( $status ),
                            ],
                            [
                                'span'       => 7,
                                'responsive' => [ 'lg' => 12 ],
                                'component'  => $this->build_next_step_card( $status ),
                            ],
                        ],
                    ],
                    [
                        'type'  => 'card',
                        'title' => __( 'Plan Coverage by Module', 'ultraguard-security-suite' ),
                        'icon'  => 'dashicons-list-view',
                        'data'  => [
                            [
                                'type'       => 'alert-box',
                                'alert_type' => 'info',
                                'title'      => __( 'See how each module maps to Free, Pro, and Agency', 'ultraguard-security-suite' ),
                                'message'    => __( 'Free users can explore the framework, while Pro and Agency unlock the advanced modules for live usage. Agency keeps the same premium toolkit but expands licensing across up to 20 sites.', 'ultraguard-security-suite' ),
                            ],
                            [
                                'type'       => 'data-table',
                                'id'         => 'ultraguard-license-feature-matrix',
                                'columns'    => [
                                    'module'      => [ 'title' => __( 'Module', 'ultraguard-security-suite' ) ],
                                    'group'       => [ 'title' => __( 'Group', 'ultraguard-security-suite' ), 'width' => '130px' ],
                                    'free'        => [ 'title' => __( 'Free', 'ultraguard-security-suite' ), 'width' => '120px' ],
                                    'pro'         => [ 'title' => __( 'Pro', 'ultraguard-security-suite' ), 'width' => '110px' ],
                                    'agency'      => [ 'title' => __( 'Agency', 'ultraguard-security-suite' ), 'width' => '150px' ],
                                    'access'      => [ 'title' => __( 'Current Access', 'ultraguard-security-suite' ), 'width' => '140px' ],
                                    'description' => [ 'title' => __( 'Why It Matters', 'ultraguard-security-suite' ) ],
                                ],
                                'data'       => $this->build_module_compare_rows(),
                                'searchable' => true,
                                'pagination' => [ 'enabled' => false ],
                            ],
                        ],
                    ],
                ],
                $feature_sections
            ),
            'form'      => [ 'enable' => false ],
        ];
    }
}
