<?php $__env->startSection('title', 'Dashboard'); ?>
<?php $__env->startSection('topbar', 'Dashboard'); ?>

<?php $__env->startPush('styles'); ?>
<style>
    .kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: .85rem; margin-bottom: 1.25rem; }
    .kpi { padding: 1rem 1.1rem; }
    .kpi-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
    .kpi-num { font-size: 1.45rem; font-weight: 800; margin-top: .2rem; }
    .dash-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1rem; }
    .event-list { display: flex; flex-direction: column; gap: .75rem; }
    .event-card {
        display: grid; grid-template-columns: 1.3fr .7fr .8fr auto; gap: 1rem; align-items: center;
        padding: 1.1rem 1.2rem; border: 1px solid var(--border); border-radius: 12px; background: #FAFBFC;
    }
    .event-card h3 { margin: 0; font-size: 1rem; font-weight: 800; }
    .event-card .meta { margin: .3rem 0 0; font-size: .8rem; color: var(--muted); }
    .usage-track { background: #F1F5F9; border-radius: 99px; height: 6px; overflow: hidden; margin-top: .35rem; }
    .usage-fill { height: 100%; background: var(--mexco-primary); border-radius: 99px; }
    .side-list { display: flex; flex-direction: column; gap: .65rem; }
    .side-item { padding: .85rem .95rem; border: 1px solid var(--border); border-radius: 10px; background: #FAFBFC; }
    .side-item strong { display: block; font-size: .88rem; }
    .side-item .meta { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
    .empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
    @media (max-width: 1100px) {
        .kpi-row { grid-template-columns: repeat(2, 1fr); }
        .dash-grid, .event-card { grid-template-columns: 1fr; }
    }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<div class="pg-head">
    <div>
        <h1>Good <?php echo e(now()->format('H') < 12 ? 'morning' : (now()->format('H') < 18 ? 'afternoon' : 'evening')); ?>, <?php echo e($user->name); ?></h1>
        <p>Your events, licenses, and billing activity.</p>
    </div>
    <div style="display:flex;gap:.5rem;flex-wrap:wrap">
        <a href="<?php echo e(route('mexco.portal.events')); ?>" class="btn-outline">My events</a>
        <?php if($canStartDemo ?? false): ?>
            <a href="<?php echo e(route('mexco.portal.demo.start')); ?>" class="btn-outline">Start free demo</a>
        <?php endif; ?>
        <?php if($activeDemo ?? null): ?>
            <a href="<?php echo e(url('/mexco')); ?>" class="btn-outline" target="_blank" rel="noopener">Visitor Pass ↗</a>
        <?php elseif(($campusApplication ?? null)?->isAwaitingReview()): ?>
            <a href="<?php echo e(route('mexco.contact')); ?>" class="btn-outline">Contact support</a>
        <?php else: ?>
            <a href="<?php echo e(route('mexco.plans')); ?>" class="btn-purple">+ Create event</a>
        <?php endif; ?>
    </div>
</div>

<?php if(($campusApplication ?? null)?->isAwaitingReview()): ?>
    <div class="card" style="padding:1.15rem 1.25rem;margin-bottom:1rem;border-color:#FDE68A;background:#FFFBEB">
        <strong style="display:block;margin-bottom:.35rem">Campus Plan: awaiting Super Admin approval</strong>
        <div style="font-size:.9rem;color:var(--muted);line-height:1.55">
            Application <code><?php echo e($campusApplication->reference_no); ?></code>
            for <strong style="color:var(--ink)"><?php echo e($campusApplication->event_name); ?></strong>
            is <strong style="color:var(--ink)"><?php echo e(strtolower($campusApplication->statusLabel())); ?></strong>.
            Your sponsored event will appear here once a Super Admin approves it.
        </div>
    </div>
<?php elseif(($campusApplication ?? null)?->isRejected()): ?>
    <div class="card" style="padding:1.15rem 1.25rem;margin-bottom:1rem;border-color:#FECACA;background:#FEF2F2">
        <strong style="display:block;margin-bottom:.35rem">Campus Plan application rejected</strong>
        <div style="font-size:.9rem;color:var(--muted);line-height:1.55;margin-bottom:.75rem">
            Application <code><?php echo e($campusApplication->reference_no); ?></code>
            <?php if($campusApplication->review_notes): ?>
                · <?php echo e($campusApplication->review_notes); ?>

            <?php endif; ?>
        </div>
        <a href="<?php echo e(route('mexco.portal.campus.apply')); ?>" class="btn-purple btn-sm">Submit a new application</a>
    </div>
<?php endif; ?>

<?php if(session('demo_organiser_username') || ($activeDemo ?? null)): ?>
    <?php
        $demoDefaults = app(\App\Services\DemoService::class)->defaultAccounts();
        $demoVisitor = app(\App\Services\DemoService::class)->primaryVisitor();
        $orgUser = session('demo_organiser_username') ?: ($activeDemo->event->organiser_username ?? null);
        $orgPass = session('demo_organiser_password') ?: ($demoDefaults['organiser']['password'] ?? '1234');
    ?>
    <div class="card" style="padding:1rem 1.15rem;margin-bottom:1rem;border-color:#BBF7D0;background:#F0FDF4">
        <strong style="display:block;margin-bottom:.5rem">Default demo logins</strong>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:.85rem">
            <div style="font-size:.86rem;color:var(--muted);line-height:1.5">
                <div style="font-weight:800;color:var(--ink);margin-bottom:.2rem">Organizer</div>
                Username: <code><?php echo e($orgUser); ?></code><br>
                Password: <code><?php echo e($orgPass); ?></code>
            </div>
            <?php if($demoVisitor): ?>
                <div style="font-size:.86rem;color:var(--muted);line-height:1.5">
                    <div style="font-weight:800;color:var(--ink);margin-bottom:.2rem">Participant (Visitor)</div>
                    Email: <code><?php echo e($demoVisitor['email']); ?></code><br>
                    IC / ID: <code><?php echo e($demoVisitor['ic']); ?></code>
                </div>
            <?php endif; ?>
        </div>
        <div style="margin-top:.75rem;display:flex;gap:.5rem;flex-wrap:wrap">
            <a href="<?php echo e(route('mexco.admin.login')); ?>" class="btn-purple btn-sm" target="_blank" rel="noopener">Open Organizer</a>
            <a href="<?php echo e(url('/mexco')); ?>" class="btn-outline btn-sm" target="_blank" rel="noopener">Open Visitor Pass</a>
        </div>
    </div>
<?php endif; ?>

<?php if($activeDemo ?? null): ?>
    <div class="card" style="padding:1rem 1.15rem;margin-bottom:1rem;border-color:#DDD6FE;background:#FAF8FF">
        <strong style="display:block;margin-bottom:.35rem">Demo license active</strong>
        <div style="font-size:.88rem;color:var(--muted)">
            <?php echo e($activeDemo->event?->name); ?> ·
            <?php if($activeDemo->isTrialActive()): ?>
                <?php echo e($activeDemo->trialDaysRemaining()); ?> day(s) remaining ·
            <?php endif; ?>
            full features with limited capacity.
            <?php if($demoLimits): ?>
                Cap: <?php echo e(number_format($demoLimits['participants'] ?? 0)); ?> participants,
                <?php echo e($demoLimits['sessions'] ?? '-'); ?> sessions,
                <?php echo e($demoLimits['booths'] ?? '-'); ?> booths.
            <?php endif; ?>
        </div>
        <div style="margin-top:.65rem;display:flex;gap:.5rem;flex-wrap:wrap">
            <a href="<?php echo e(url('/mexco')); ?>" class="btn-purple btn-sm" target="_blank" rel="noopener">Open Visitor Pass</a>
            <a href="<?php echo e(route('mexco.admin.login')); ?>" class="btn-outline btn-sm">Manage in Organizer</a>
            <a href="<?php echo e(route('mexco.plans')); ?>" class="btn-outline btn-sm">Upgrade plan</a>
        </div>
        <?php if($activeDemo->event_id): ?>
            <div style="margin-top:.65rem;font-size:.8rem;color:var(--muted)">
                Your demo event ID: <code><?php echo e($activeDemo->event_id); ?></code>
                · Shared sandbox event: <code><?php echo e($demoDefaults['event_id']); ?></code>
            </div>
        <?php endif; ?>
    </div>
<?php elseif($canStartDemo ?? false): ?>
    <div class="card" style="padding:1rem 1.15rem;margin-bottom:1rem;border-color:#DDD6FE;background:#FAF8FF">
        <strong style="display:block;margin-bottom:.35rem">Try MeXCo free</strong>
        <div style="font-size:.88rem;color:var(--muted);margin-bottom:.65rem">
            Start a demo event with full features and limited capacity. No payment required.
        </div>
        <a href="<?php echo e(route('mexco.portal.demo.start')); ?>" class="btn-purple btn-sm">Start free demo</a>
    </div>
<?php endif; ?>

<div class="kpi-row">
    <div class="card kpi"><div class="kpi-label">Total events</div><div class="kpi-num"><?php echo e($kpis['total']); ?></div></div>
    <div class="card kpi"><div class="kpi-label">Upcoming</div><div class="kpi-num"><?php echo e($kpis['upcoming']); ?></div></div>
    <div class="card kpi"><div class="kpi-label">Ongoing</div><div class="kpi-num" style="color:var(--mexco-success)"><?php echo e($kpis['ongoing']); ?></div></div>
    <div class="card kpi"><div class="kpi-label">Completed</div><div class="kpi-num"><?php echo e($kpis['completed']); ?></div></div>
    <div class="card kpi"><div class="kpi-label">Participants</div><div class="kpi-num"><?php echo e(number_format($kpis['participants'])); ?></div></div>
</div>

<?php if($openOrders->isNotEmpty()): ?>
    <div class="card" style="padding:1rem 1.15rem;margin-bottom:1rem;border-color:#DDD6FE;background:#FAF8FF">
        <strong style="display:block;margin-bottom:.55rem">Continue checkout</strong>
        <?php $__currentLoopData = $openOrders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div style="display:flex;justify-content:space-between;gap:1rem;flex-wrap:wrap;align-items:center;padding:.35rem 0">
                <div>
                    <div style="font-weight:700"><?php echo e($order->event?->name ?? 'New event'); ?> · <?php echo e($order->plan?->name); ?></div>
                    <div style="font-size:.8rem;color:var(--muted)"><?php echo e($order->statusLabel()); ?> · <?php echo e($order->reference_no); ?></div>
                </div>
                <div>
                    <?php if($order->status === 'pending_payment'): ?>
                        <a href="<?php echo e(route('mexco.checkout.resume', $order)); ?>" class="btn-purple btn-sm">Complete payment</a>
                    <?php else: ?>
                        <a href="<?php echo e(route('mexco.checkout.resume', $order)); ?>" class="btn-purple btn-sm">Continue</a>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
<?php endif; ?>

<div class="dash-grid">
    <div class="card" style="padding:1.15rem 1.2rem">
        <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;gap:1rem;flex-wrap:wrap">
            <h2 style="margin:0;font-size:1.05rem;font-weight:800">Your events</h2>
            <a href="<?php echo e(route('mexco.portal.events')); ?>" class="btn-outline btn-sm">View all</a>
        </div>
        <div class="event-list">
            <?php $__empty_1 = true; $__currentLoopData = $rows->take(5); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <?php
                    $event = $row['event'];
                    $u = $row['usage'];
                    $pct = min(100, (float) ($u['percent'] ?? 0));
                ?>
                <article class="event-card">
                    <div>
                        <h3><?php echo e($event->name); ?></h3>
                        <p class="meta"><?php echo e($row['schedule']); ?> · <?php echo e($organisation?->name); ?></p>
                        <?php if($row['addons']): ?>
                            <p class="meta">Add-ons: <?php echo e(implode(', ', $row['addons'])); ?></p>
                        <?php endif; ?>
                    </div>
                    <div>
                        <?php if($event->license?->plan): ?>
                            <span class="plan-pill <?php echo e($event->license->plan->code); ?>"><?php echo e($event->license->plan->name); ?></span>
                        <?php endif; ?>
                        <div class="meta" style="margin-top:.35rem"><?php echo e($row['statusLabel']); ?>

                            <?php if($row['licenseStatus'] === 'pending'): ?> · License pending <?php endif; ?>
                            <?php if($row['licenseStatus'] === 'active'): ?> · License active <?php endif; ?>
                        </div>
                    </div>
                    <div>
                        <?php if($u['limit']): ?>
                            <div style="font-size:.8rem;font-weight:700"><?php echo e(number_format($u['current'])); ?> / <?php echo e(number_format($u['limit'])); ?></div>
                            <div class="usage-track"><div class="usage-fill" style="width:<?php echo e($pct); ?>%"></div></div>
                            <div class="meta">participants</div>
                        <?php else: ?>
                            <div style="font-size:.8rem;font-weight:700"><?php echo e(number_format($u['current'])); ?> participants</div>
                        <?php endif; ?>
                    </div>
                    <div style="display:flex;gap:.4rem;flex-wrap:wrap">
                        <a href="<?php echo e(route('mexco.admin.login')); ?>" class="btn-purple btn-sm">Manage event</a>
                    </div>
                </article>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="empty">
                    <strong style="display:block;color:var(--ink);margin-bottom:.35rem">No events yet</strong>
                    Choose a plan and create your first event license.
                    <div style="margin-top:1rem">
                        <a href="<?php echo e(route('mexco.plans')); ?>" class="btn-purple">Create your event</a>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>

    <div style="display:flex;flex-direction:column;gap:1rem">
        <div class="card" style="padding:1.15rem">
            <h2 style="margin:0 0 .85rem;font-size:1.05rem;font-weight:800">License snapshot</h2>
            <div class="side-list">
                <div class="side-item">
                    <strong>Current plan</strong>
                    <div class="meta"><?php echo e($currentPlan?->name ?? 'No active plan yet'); ?></div>
                </div>
                <div class="side-item">
                    <strong>Upcoming expiry</strong>
                    <div class="meta"><?php echo e($upcomingExpiry ? $upcomingExpiry->format('j M Y') : 'Not set'); ?></div>
                </div>
            </div>
        </div>

        <div class="card" style="padding:1.15rem">
            <h2 style="margin:0 0 .85rem;font-size:1.05rem;font-weight:800">Billing</h2>
            <div class="side-list">
                <?php $__empty_1 = true; $__currentLoopData = $pendingInvoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inv): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="side-item">
                        <strong><?php echo e($inv->invoice_number); ?></strong>
                        <div class="meta"><?php echo e($inv->event?->name); ?> · <?php echo e($inv->statusLabel()); ?> · <?php echo e($inv->currency); ?> <?php echo e(number_format($inv->total_cents / 100, 0)); ?></div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="meta" style="color:var(--muted);font-size:.85rem">No open invoices.</div>
                <?php endif; ?>
            </div>
            <h3 style="margin:1rem 0 .55rem;font-size:.85rem;font-weight:800;color:var(--muted);text-transform:uppercase;letter-spacing:.04em">Recent payments</h3>
            <div class="side-list">
                <?php $__empty_1 = true; $__currentLoopData = $recentPayments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="side-item">
                        <strong><?php echo e($payment->currency); ?> <?php echo e(number_format($payment->amount_cents / 100, 0)); ?></strong>
                        <div class="meta"><?php echo e($payment->invoice?->event?->name); ?> · <?php echo e(optional($payment->paid_at)->format('j M Y')); ?></div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="meta" style="color:var(--muted);font-size:.85rem">No payments yet.</div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('portal.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\myapp\resources\views/portal/dashboard.blade.php ENDPATH**/ ?>