@extends('layouts.app-shell')
@section('title', 'Admin Dashboard')
@section('bottomnav')
    <a href="{{ route('admin.dashboard') }}" class="{{ request()->routeIs('admin.dashboard') ? 'active' : '' }}"><x-icon name="home" :size="20" /><span>Home</span></a>
    <a href="{{ route('admin.bookings') }}" class="{{ request()->routeIs('admin.bookings*') ? 'active' : '' }}"><x-icon name="bookings" :size="20" /><span>Subs</span></a>
    <a href="{{ route('admin.partners') }}" class="{{ request()->routeIs('admin.partners*') ? 'active' : '' }}"><x-icon name="profile" :size="20" /><span>Partners</span></a>
    <a href="{{ route('admin.services.index') }}" class="{{ request()->routeIs('admin.services*') ? 'active' : '' }}"><x-icon name="services" :size="20" /><span>Catalogue</span></a>
@endsection
@section('sidebar')
    @include('admin._sidebar')
@endsection

@section('content')
<div class="kpi-grid">
    <div class="kpi k1"><div class="lbl">Monthly revenue</div><div class="val">₹{{ number_format(($stats['revenue'] ?? 0)/100, 0) }}</div><div class="delta">from active subscriptions</div></div>
    <div class="kpi k2"><div class="lbl">Active subscriptions</div><div class="val">{{ $stats['active_subs'] ?? 0 }}</div><div class="delta">{{ $stats['bookings'] }} total</div></div>
    <div class="kpi k3"><div class="lbl">Partners</div><div class="val">{{ $stats['partners'] }}</div><div class="delta">{{ $stats['pending_partners'] }} pending</div></div>
    <div class="kpi k4"><div class="lbl">Customers</div><div class="val">{{ $stats['customers'] }}</div><div class="delta">all-time</div></div>
</div>

<div class="grid-2" style="grid-template-columns: 2fr 1fr;">
    <div class="panel">
        <div class="panel-head">
            <h3>Recent subscriptions</h3>
            <a href="{{ route('admin.bookings') }}" class="btn btn-ghost btn-sm">View all →</a>
        </div>
        <div class="table-wrap">
            <table class="table">
                <thead><tr><th>Code</th><th>Service</th><th>Customer</th><th>Partner</th><th>Status</th><th>Monthly</th></tr></thead>
                <tbody>
                @forelse($recent as $b)
                    <tr>
                        <td><a href="{{ route('admin.bookings.show', $b) }}"><span class="code">{{ $b->booking_code }}</span></a></td>
                        <td>{{ $b->service->name }}</td>
                        <td>{{ $b->customer_name }}</td>
                        <td>{{ $b->partner?->display_name ?? '—' }}</td>
                        <td><span class="pill pill-{{ $b->status_color }}">{{ $b->display_status }}</span></td>
                        <td>₹{{ number_format($b->total_rupees, 0) }}</td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="empty">No subscriptions yet.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="panel">
        <div class="panel-head"><h3>Recent partners</h3><a href="{{ route('admin.partners') }}" class="btn btn-ghost btn-sm">View all →</a></div>
        <div class="table-wrap">
            <table class="table">
                <thead><tr><th>Name</th><th>Status</th></tr></thead>
                <tbody>
                @forelse($recentPartners as $p)
                    <tr>
                        <td><a href="{{ route('admin.partners.show', $p->user) }}">{{ $p->display_name }}</a></td>
                        <td>{!! $p->user->is_partner_approved ? '<span class="pill pill-green">approved</span>' : '<span class="pill pill-gold">pending</span>' !!}</td>
                    </tr>
                @empty
                    <tr><td colspan="2" class="empty">No partners yet.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection