@extends('layouts.admin')

@section('title', 'Payment analytics')

@section('content')
<div class="admin-top">
    <div>
        <h1>Revenue analytics</h1>
        <p class="sub">Succeeded payments only (stored transactions).</p>
    </div>
    <a href="{{ route('admin.transactions.index') }}" class="btn btn-ghost">Transactions</a>
</div>

<div class="stats">
    <div class="stat">
        <label>Successful payments</label>
        <span>{{ number_format($success) }}</span>
    </div>
    <div class="stat">
        <label>Failed payments</label>
        <span>{{ number_format($failed) }}</span>
    </div>
</div>

<div class="card">
    <h2 style="font-size:1rem; margin-top:0;">Last 14 days (daily revenue)</h2>
    <table class="admin-table">
        <thead><tr><th>Date</th><th>Total</th><th>Count</th></tr></thead>
        <tbody>
            @forelse($daily as $row)
                <tr>
                    <td>{{ $row->d }}</td>
                    <td>${{ number_format($row->total, 2) }}</td>
                    <td>{{ $row->c }}</td>
                </tr>
            @empty
                <tr><td colspan="3">No data yet.</td></tr>
            @endforelse
        </tbody>
    </table>
</div>

<div class="card">
    <h2 style="font-size:1rem; margin-top:0;">By gateway</h2>
    <table class="admin-table">
        <thead><tr><th>Gateway</th><th>Total</th><th>Count</th></tr></thead>
        <tbody>
            @forelse($byGateway as $row)
                <tr>
                    <td>{{ $row->gateway }}</td>
                    <td>${{ number_format($row->total, 2) }}</td>
                    <td>{{ $row->c }}</td>
                </tr>
            @empty
                <tr><td colspan="3">No data yet.</td></tr>
            @endforelse
        </tbody>
    </table>
</div>
@endsection
