@extends('admin.layout')

@section('title', 'RapidSewa Dashboard')

@section('body')
<div class="shell">
    @include('admin.partials.sidebar')
    <main class="main">
        <div class="topbar">
            <div><h1>Today Management</h1><div class="crumb">Dashboard, expert management, customer management, graph and income</div></div>
            @include('admin.partials.logout')
        </div>
        <section class="grid">
            @foreach ($stats as $stat)
                <div class="stat tone-{{ $stat['tone'] }}"><span>{{ $stat['label'] }}</span><strong>{{ $stat['value'] }}</strong></div>
            @endforeach
        </section>
        <section class="map-grid">
            <div class="panel">
                <h2>Business Graph</h2>
                @php $max = max($graph); @endphp
                @foreach ($graph as $label => $value)
                    <p><strong>{{ $label }}</strong> <span class="muted">{{ $value }}</span></p>
                    <div class="bar"><span style="width:{{ min(100, ($value / $max) * 100) }}%"></span></div>
                @endforeach
            </div>
            <div class="panel">
                <h2>Income</h2>
                <p><span class="muted">Paid Revenue</span><strong style="display:block;font-size:28px">Rs {{ number_format((float) $income['paid'], 2) }}</strong></p>
                <p><span class="muted">Refunds</span><strong style="display:block">Rs {{ number_format((float) $income['refunds'], 2) }}</strong></p>
                <p><span class="muted">Vendor Wallet</span><strong style="display:block">Rs {{ number_format((float) $income['vendor_wallet'], 2) }}</strong></p>
            </div>
        </section>
        <section class="panel">
            <h2>Latest Service Bookings</h2>
            <table>
                <tr><th>Service ID</th><th>Order Number</th><th>User</th><th>Amount</th><th>Status</th><th>Payment</th></tr>
                @foreach ($latestBookings as $row)
                    <tr><td>{{ $row->id }}</td><td>{{ $row->booking_number }}</td><td>{{ $row->user_id }}</td><td>{{ $row->payable_total }}</td><td>{{ $row->status }}</td><td>{{ $row->payment_status }}</td></tr>
                @endforeach
            </table>
        </section>
        <section class="panel">
            <h2>Expert Management Snapshot</h2>
            <table>
                <tr><th>Code</th><th>Vendor</th><th>Online</th><th>Wallet</th><th>Services Done</th><th>Docs</th></tr>
                @foreach ($latestVendors as $row)
                    <tr><td>{{ $row->pro_code }}</td><td>{{ $row->vendor_business_name }}</td><td>{{ $row->online_status }}</td><td>{{ $row->wallet_balance }}</td><td>{{ $row->services_done_count }}</td><td>{{ $row->document_status }}</td></tr>
                @endforeach
            </table>
        </section>
    </main>
</div>
@endsection
