@extends('layouts.app')

@section('title', 'Platform Billing')
@section('page-title', 'Billing')
@section('page-subtitle', 'Manual subscription payment approvals and invoices')

@section('content')
<div class="card border-0 shadow-sm mb-4">
    <div class="card-header bg-white fw-semibold">Payment approvals</div>
    <div class="table-responsive">
        <table class="table mb-0"><thead><tr><th>Tenant</th><th>Plan</th><th>Amount</th><th>Reference</th><th>Status</th><th></th></tr></thead><tbody>
            @foreach($payments as $payment)
                <tr>
                    <td>{{ $payment->tenant?->name }}</td><td>{{ $payment->plan?->name }}</td><td>{{ number_format($payment->amount, 2) }}</td><td>{{ $payment->reference }}</td><td>{{ $payment->status }}</td>
                    <td class="text-end">
                        @if($payment->proof_path)<a class="btn btn-sm btn-outline-secondary" href="{{ asset('uploads/'.$payment->proof_path) }}" target="_blank">Proof</a>@endif
                        @if($payment->status === 'pending')
                            <form method="POST" class="d-inline" action="{{ route('super.billing.approve', $payment) }}">@csrf<button class="btn btn-sm btn-success">Approve</button></form>
                            <form method="POST" class="d-inline" action="{{ route('super.billing.reject', $payment) }}">@csrf<input type="hidden" name="rejected_reason" value="Payment proof was not accepted."><button class="btn btn-sm btn-outline-danger">Reject</button></form>
                        @endif
                    </td>
                </tr>
            @endforeach
        </tbody></table>
    </div>
    <div class="card-body">{{ $payments->links() }}</div>
</div>

<div class="card border-0 shadow-sm">
    <div class="card-header bg-white fw-semibold">Recent invoices</div>
    <div class="table-responsive">
        <table class="table mb-0"><thead><tr><th>Invoice</th><th>Tenant</th><th>Amount</th><th>Status</th><th>Paid</th></tr></thead><tbody>
            @foreach($invoices as $invoice)
                <tr><td>{{ $invoice->invoice_number }}</td><td>{{ $invoice->tenant?->name }}</td><td>{{ number_format($invoice->amount, 2) }}</td><td>{{ $invoice->status }}</td><td>{{ app_date($invoice->paid_at) }}</td></tr>
            @endforeach
        </tbody></table>
    </div>
</div>
@endsection
