@extends('layouts.dashboard')
@section('title', 'Invoice ' . $invoice->invoice_number)
@section('page-title', 'Invoice ' . $invoice->invoice_number)
@section('content')
<div class="row">
    <div class="col-lg-8">
        <div class="content-card">
            <div class="d-flex justify-content-between mb-4">
                <div>
                    <h2 class="mb-0">{{ $invoice->invoice_number }}</h2>
                    <span class="badge {{ $invoice->statusBadgeClass() }} mt-2">{{ ucfirst($invoice->status) }}</span>
                </div>
                <div class="text-end">
                    <h2 class="text-accent">${{ number_format($invoice->amount, 2) }} <small>{{ $invoice->currency }}</small></h2>
                    <small class="text-muted">{{ $invoice->created_at->format('M d, Y') }}</small>
                </div>
            </div>
            <hr>
            <table class="table">
                <thead><tr><th>Description</th><th class="text-end">Amount</th></tr></thead>
                <tbody>
                <tr>
                    <td>{{ $invoice->package->name ?? 'Custom invoice' }}
                        @if($invoice->package)<br><small class="text-muted">{{ $invoice->package->blogs_count }} blogs (lifetime)</small>@endif
                    </td>
                    <td class="text-end">${{ number_format($invoice->amount, 2) }}</td>
                </tr>
                </tbody>
                <tfoot><tr><th>Total</th><th class="text-end">${{ number_format($invoice->amount, 2) }} {{ $invoice->currency }}</th></tr></tfoot>
            </table>
            @if($invoice->notes)<p class="text-muted">{{ $invoice->notes }}</p>@endif
        </div>
    </div>
    <div class="col-lg-4">
        <div class="content-card">
            @if($invoice->isUnpaid())
                <h4>Pay this invoice</h4>
                <p class="text-muted">Choose a secure payment gateway.</p>
                @if(gateway_enabled('paypal'))
                    <a href="{{ route('reseller.invoices.pay', [$invoice, 'gateway' => 'paypal']) }}" class="btn btn-warning w-100 btn-lg mb-2">Pay with PayPal</a>
                @endif
                @if(gateway_enabled('tap'))
                    <a href="{{ route('reseller.invoices.pay', [$invoice, 'gateway' => 'tap']) }}" class="btn btn-dark w-100">Pay with Tap</a>
                @endif
                @if(!gateway_enabled('paypal') && !gateway_enabled('tap'))
                    <p class="text-muted mb-0">No payment gateway is currently enabled.</p>
                @endif
            @else
                <h4>Paid</h4>
                <p class="text-success mb-1">✓ Paid {{ $invoice->paid_at?->format('M d, Y') }}</p>
                @if($invoice->transaction_id)<p class="small">Txn: <code>{{ $invoice->transaction_id }}</code></p>@endif
            @endif
            <a href="{{ route('reseller.invoices.index') }}" class="btn btn-link w-100 mt-2">← Back</a>
        </div>
    </div>
</div>
@endsection
