<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{{ $receipt->receipt_number }}</title>
    @include('receipts.partials.pdf-styles')
</head>
<body>
@php
    $company = $company ?? \App\Models\CompanySetting::getSettings();
@endphp
<div class="container pdf-root">
    <table class="layout section" cellspacing="0" cellpadding="0" width="100%">
        <tr>
            <td class="text-center font-bold" style="font-size:16px;padding-bottom:8px;">{{ $company->company_name ?? config('app.name') }}</td>
        </tr>
        @if($company->company_logo && \Illuminate\Support\Facades\Storage::disk('public')->exists($company->company_logo))
        <tr><td class="text-center" style="padding-bottom:8px;">
            <img src="{{ \Illuminate\Support\Facades\Storage::url($company->company_logo) }}" alt="" style="max-width:100px;max-height:52px;">
        </td></tr>
        @endif
        <tr><td class="text-center" style="font-size:10px;color:#6b7280;">
            @if($company->company_address ?? null){{ $company->company_address }}<br>@endif
            @if($company->company_phone ?? null){{ $company->company_phone }}@endif
            @if($company->company_email ?? null)@if($company->company_phone ?? null) · @endif{{ $company->company_email }}@endif
        </td></tr>
    </table>

    <table class="layout section" cellspacing="0" cellpadding="0" width="100%">
        <tr><td class="text-center font-bold border-b" style="font-size:13px;padding:10px 0;">PAYMENT RECEIPT</td></tr>
    </table>

    <table class="layout section" cellspacing="0" cellpadding="0" width="100%">
        <tr><td width="40%" class="label-muted">Receipt #</td><td class="text-right font-bold">{{ $receipt->receipt_number }}</td></tr>
        <tr><td class="label-muted">Date</td><td class="text-right">{{ $receipt->created_at->format('M d, Y') }}</td></tr>
        @if($payment->invoice ?? null)
        <tr><td class="label-muted">Invoice</td><td class="text-right font-bold">{{ $payment->invoice->invoice_number }}</td></tr>
        @endif
        <tr><td class="label-muted">Method</td><td class="text-right">{{ ucfirst(str_replace('_', ' ', (string) ($receipt->payment_method ?? '—'))) }}</td></tr>
    </table>

    <table class="layout section" cellspacing="0" cellpadding="0" width="100%">
        <tr><td class="label-muted">Paid by</td></tr>
        <tr><td class="font-bold">{{ optional($payment->customer)->name ?? 'Customer' }}</td></tr>
        @if(filled(optional($payment->customer)->email))
        <tr><td style="font-size:10px;color:#6b7280;">{{ $payment->customer->email }}</td></tr>
        @endif
    </table>

    <table class="layout section" cellspacing="0" cellpadding="0" width="100%" style="border:1px solid #e5e7eb;background:#f9fafb;">
        <tr><td colspan="2" class="text-center amount-lg" style="border-bottom:1px solid #e5e7eb;">
            {{ $payment->currency ?? 'USD' }} {{ number_format((float) $receipt->amount, 2) }}
        </td></tr>
        @if($receipt->transaction_reference)
        <tr><td class="label-muted">Reference</td><td class="text-right">{{ $receipt->transaction_reference }}</td></tr>
        @endif
    </table>

    @if($receipt->notes)
    <table class="layout section" cellspacing="0" cellpadding="0" width="100%">
        <tr><td class="label-muted">Notes</td></tr>
        <tr><td style="font-size:11px;">{{ $receipt->notes }}</td></tr>
    </table>
    @endif
</div>
</body>
</html>
