<?php $__env->startSection('title', 'SaaS Super Admin Control Panel'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-8" x-data="{ dateRange: 'this_month' }">

    <!-- Top Executive Header -->
    <div class="govix-page-hero flex flex-col lg:flex-row lg:items-center justify-between gap-4 px-1 py-2 rounded-3xl bg-white text-slate-900">
        <div>
            <div class="flex items-center space-x-2 rtl:space-x-reverse text-[10px] font-bold text-orange-600 mb-1 uppercase tracking-wider">
                <span>UAE Typing Center SaaS ERP</span>
                <span>•</span>
                <span class="px-2 py-0.5 rounded bg-orange-50 text-orange-600">Platform Control Console</span>
            </div>
            <h1 class="text-2xl font-bold tracking-tight text-slate-900">Welcome back, <?php echo e(auth()->user()->name); ?> 👋</h1>
            <p class="text-xs text-slate-500 mt-1">Platform-wide overview of tenant growth, recurring subscription revenue, resource usage, and security alerts.</p>
        </div>

        <!-- Date Filters (Requirement 3) -->
        <div class="flex items-center space-x-2 rtl:space-x-reverse bg-white p-1.5 rounded-2xl border border-slate-200 text-xs shadow-sm">
            <button @click="dateRange = 'today'" :class="dateRange === 'today' ? 'bg-sky-600 text-white font-bold' : 'text-slate-400 hover:text-white'" class="px-3 py-1.5 rounded-xl transition-all">Today</button>
            <button @click="dateRange = '7days'" :class="dateRange === '7days' ? 'bg-sky-600 text-white font-bold' : 'text-slate-400 hover:text-white'" class="px-3 py-1.5 rounded-xl transition-all">Last 7 Days</button>
            <button @click="dateRange = 'this_month'" :class="dateRange === 'this_month' ? 'bg-sky-600 text-white font-bold' : 'text-slate-400 hover:text-white'" class="px-3 py-1.5 rounded-xl transition-all">This Month</button>
            <a href="<?php echo e(route('platform.tenants.create')); ?>" class="px-4 py-1.5 bg-orange-600 hover:bg-orange-700 text-white font-bold rounded-xl shadow-lg transition-all">+ New Tenant Wizard</a>
        </div>
    </div>

    <!-- Main KPI Cards Grid (Requirement 3) -->
    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-5">
        <div class="p-5 rounded-3xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700/60 shadow-sm relative overflow-hidden">
            <div class="flex items-center justify-between text-slate-400 mb-2">
                <span class="text-xs font-bold uppercase tracking-wider">Total Tenants</span>
                <span class="px-2 py-0.5 rounded bg-sky-50 dark:bg-sky-950 text-sky-600 font-bold text-[10px]">Registered</span>
            </div>
            <div class="text-3xl font-extrabold text-slate-900 dark:text-white"><?php echo e($stats['total_tenants']); ?></div>
            <div class="flex items-center justify-between text-xs text-slate-400 mt-3 pt-3 border-t border-slate-100 dark:border-slate-700/60">
                <span><?php echo e($stats['active_tenants']); ?> Active</span>
                <span class="text-emerald-500 font-bold"><?php echo e($stats['trial_tenants']); ?> In Trial</span>
            </div>
        </div>

        <div class="p-5 rounded-3xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700/60 shadow-sm relative overflow-hidden">
            <div class="flex items-center justify-between text-slate-400 mb-2">
                <span class="text-xs font-bold uppercase tracking-wider">Monthly Recurring Revenue (MRR)</span>
                <span class="px-2 py-0.5 rounded bg-emerald-50 dark:bg-emerald-950 text-emerald-600 font-bold text-[10px]">SaaS Billing</span>
            </div>
            <div class="text-3xl font-extrabold text-emerald-600 dark:text-emerald-400">AED <?php echo e(number_format($stats['active_subscriptions'] * 699, 2)); ?></div>
            <div class="flex items-center justify-between text-xs text-slate-400 mt-3 pt-3 border-t border-slate-100 dark:border-slate-700/60">
                <span>ARR: AED <?php echo e(number_format($stats['active_subscriptions'] * 699 * 12, 2)); ?></span>
                <span class="text-emerald-500 font-bold">↑ 12% MoM</span>
            </div>
        </div>

        <div class="p-5 rounded-3xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700/60 shadow-sm relative overflow-hidden">
            <div class="flex items-center justify-between text-slate-400 mb-2">
                <span class="text-xs font-bold uppercase tracking-wider">Outstanding Invoices</span>
                <span class="px-2 py-0.5 rounded bg-rose-50 dark:bg-rose-950 text-rose-600 font-bold text-[10px]">Payment Due</span>
            </div>
            <div class="text-3xl font-extrabold text-rose-600 dark:text-rose-400">AED <?php echo e(number_format($stats['upcoming_renewals'] * 699, 2)); ?></div>
            <div class="flex items-center justify-between text-xs text-slate-400 mt-3 pt-3 border-t border-slate-100 dark:border-slate-700/60">
                <span><?php echo e($stats['upcoming_renewals']); ?> Renewals Due</span>
                <a href="<?php echo e(route('platform.billing.invoices')); ?>" class="text-sky-600 font-bold hover:underline">View Invoices ➔</a>
            </div>
        </div>

        <div class="p-5 rounded-3xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700/60 shadow-sm relative overflow-hidden">
            <div class="flex items-center justify-between text-slate-400 mb-2">
                <span class="text-xs font-bold uppercase tracking-wider">Active ERP Users</span>
                <span class="px-2 py-0.5 rounded bg-purple-50 dark:bg-purple-950 text-purple-600 font-bold text-[10px]">Platform Staff</span>
            </div>
            <div class="text-3xl font-extrabold text-slate-900 dark:text-white"><?php echo e($stats['total_users']); ?></div>
            <div class="flex items-center justify-between text-xs text-slate-400 mt-3 pt-3 border-t border-slate-100 dark:border-slate-700/60">
                <span><?php echo e($stats['active_users']); ?> Online Today</span>
                <span class="text-purple-500 font-bold">100% Isolated</span>
            </div>
        </div>
    </div>

    <!-- Super Admin Active Alerts Section (Requirement 5) -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl p-6 border border-slate-200 dark:border-slate-700/60 shadow-sm space-y-4">
        <div class="flex items-center justify-between">
            <h3 class="text-xs font-bold text-slate-900 dark:text-white uppercase tracking-wider flex items-center space-x-2 rtl:space-x-reverse">
                <span class="w-2.5 h-2.5 rounded-full bg-rose-500 animate-pulse"></span>
                <span>Actionable Platform Alerts</span>
            </h3>
            <span class="text-[11px] text-slate-400">System Monitoring Engine</span>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-xs">
            <a href="<?php echo e(route('platform.billing.invoices')); ?>" class="p-4 rounded-2xl bg-amber-50 dark:bg-amber-950/40 border border-amber-200 dark:border-amber-800/50 flex items-start space-x-3 rtl:space-x-reverse hover:border-amber-400 transition-all">
                <div class="w-8 h-8 rounded-lg bg-amber-500/20 text-amber-600 flex items-center justify-center shrink-0">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>
                </div>
                <div>
                    <h4 class="font-bold text-amber-900 dark:text-amber-200">Subscription Renewals Due</h4>
                    <p class="text-[11px] text-amber-700 dark:text-amber-300 mt-0.5"><?php echo e($stats['upcoming_renewals']); ?> tenant subscriptions expire within 30 days.</p>
                </div>
            </a>

            <a href="<?php echo e(route('platform.support')); ?>" class="p-4 rounded-2xl bg-sky-50 dark:bg-sky-950/40 border border-sky-200 dark:border-sky-800/50 flex items-start space-x-3 rtl:space-x-reverse hover:border-sky-400 transition-all">
                <div class="w-8 h-8 rounded-lg bg-sky-500/20 text-sky-600 flex items-center justify-center shrink-0">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 5.636l-3.536 3.536m0 5.656l3.536 3.536M9.172 9.172L5.636 5.636m3.536 9.192l-3.536 3.536M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-5 0a4 4 0 11-8 0 4 4 0 018 0z"/></svg>
                </div>
                <div>
                    <h4 class="font-bold text-sky-900 dark:text-sky-200">Support Desk Requests</h4>
                    <p class="text-[11px] text-sky-700 dark:text-sky-300 mt-0.5">Tenant helpdesk tickets active for platform staff review.</p>
                </div>
            </a>

            <a href="<?php echo e(route('platform.usage')); ?>" class="p-4 rounded-2xl bg-emerald-50 dark:bg-emerald-950/40 border border-emerald-200 dark:border-emerald-800/50 flex items-start space-x-3 rtl:space-x-reverse hover:border-emerald-400 transition-all">
                <div class="w-8 h-8 rounded-lg bg-emerald-500/20 text-emerald-600 flex items-center justify-center shrink-0">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/></svg>
                </div>
                <div>
                    <h4 class="font-bold text-emerald-900 dark:text-emerald-200">Resource Quota Monitors</h4>
                    <p class="text-[11px] text-emerald-700 dark:text-emerald-300 mt-0.5">Storage, AI tokens, and WhatsApp credit usage normal.</p>
                </div>
            </a>
        </div>
    </div>

    <!-- Registered Tenants & Real-Time Audit Log Grid (Requirement 6, 7) -->
    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">

        <!-- Registered Tenants Table (2 Columns) -->
        <div class="lg:col-span-2 bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700/60 shadow-sm overflow-hidden flex flex-col justify-between">
            <div>
                <div class="p-4 border-b border-slate-200 dark:border-slate-700 flex items-center justify-between">
                    <h3 class="text-xs font-bold text-slate-900 dark:text-white uppercase tracking-wider">Registered Typing Center Tenants</h3>
                    <a href="<?php echo e(route('platform.tenants')); ?>" class="text-xs text-sky-600 dark:text-sky-400 font-bold hover:underline">View All ➔</a>
                </div>

                <div class="overflow-x-auto">
                    <table class="w-full text-left rtl:text-right text-xs">
                        <thead class="bg-slate-50 dark:bg-slate-900/60 border-b border-slate-200 dark:border-slate-700 text-slate-500 uppercase tracking-wider font-bold">
                            <tr>
                                <th class="px-5 py-3">Tenant Company</th>
                                <th class="px-5 py-3">Emirate</th>
                                <th class="px-5 py-3">Plan</th>
                                <th class="px-5 py-3">Status</th>
                                <th class="px-5 py-3 text-right rtl:text-left">Action</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-slate-200 dark:divide-slate-700/60 font-medium">
                            <?php $__currentLoopData = $recentTenants; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tenant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr class="hover:bg-slate-50 dark:hover:bg-slate-700/30">
                                    <td class="px-5 py-3.5">
                                        <div class="font-bold text-slate-900 dark:text-white"><?php echo e($tenant->company_name); ?></div>
                                        <div class="text-[11px] text-slate-400 font-normal"><?php echo e($tenant->email); ?></div>
                                    </td>
                                    <td class="px-5 py-3.5 text-slate-700 dark:text-slate-300 font-medium"><?php echo e($tenant->emirate); ?></td>
                                    <td class="px-5 py-3.5">
                                        <span class="px-2.5 py-0.5 rounded-full bg-purple-100 dark:bg-purple-950 text-purple-700 dark:text-purple-300 text-[10px] font-bold">
                                            <?php echo e($tenant->subscription->plan->name ?? 'Professional Plan'); ?>

                                        </span>
                                    </td>
                                    <td class="px-5 py-3.5">
                                        <span class="px-2.5 py-0.5 rounded-full bg-emerald-100 dark:bg-emerald-950 text-emerald-700 dark:text-emerald-300 text-[10px] font-bold">Active</span>
                                    </td>
                                    <td class="px-5 py-3.5 text-right rtl:text-left">
                                        <a href="<?php echo e(route('platform.tenants.show', $tenant->id)); ?>" class="text-sky-600 font-bold hover:underline">Tenant 360 ➔</a>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <!-- Recent Audit Log Feed (1 Column) (Requirement 6) -->
        <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700/60 shadow-sm p-5 space-y-4">
            <div class="flex items-center justify-between border-b border-slate-200 dark:border-slate-700 pb-3">
                <h3 class="text-xs font-bold text-slate-900 dark:text-white uppercase tracking-wider">Real-Time Platform Activity</h3>
                <a href="<?php echo e(route('platform.security.audit')); ?>" class="text-[11px] text-sky-600 font-bold">Full Audit ➔</a>
            </div>

            <div class="space-y-3 overflow-y-auto max-h-[340px] text-xs">
                <?php $__currentLoopData = $recentAuditLogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="p-3 rounded-2xl bg-slate-50 dark:bg-slate-900/60 border border-slate-100 dark:border-slate-700/50 space-y-1">
                        <div class="flex items-center justify-between">
                            <span class="font-bold text-slate-800 dark:text-slate-200"><?php echo e($log->user ? $log->user->name : 'System'); ?></span>
                            <span class="text-[10px] text-slate-400 font-mono"><?php echo e($log->created_at->diffForHumans()); ?></span>
                        </div>
                        <p class="text-slate-500 dark:text-slate-400 text-[11px] font-semibold"><?php echo e($log->action); ?></p>
                        <div class="text-[10px] text-slate-400 font-mono truncate">Module: <?php echo e($log->module); ?> • IP: <?php echo e($log->ip_address ?? '127.0.0.1'); ?></div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        </div>

    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\typingcenter\resources\views/platform/dashboard.blade.php ENDPATH**/ ?>