<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{{ $payment->payment_number ?? 'Receipt' }}</title>
    @include('receipts.partials.pdf-styles')
    <style>
        body { font-family: DejaVu Sans Mono, DejaVu Sans, monospace; font-size: 11px; }
        .dash { border-top: 1px dashed #000; border-bottom: 1px dashed #000; padding: 8px 0; margin: 8px 0; }
        .row td { padding: 4px 6px; }
        .row td:last-child { text-align: right; }
    </style>
</head>
<body>
@php
    $companySettings = \App\Models\CompanySetting::getSettings();
@endphp
<div class="container pdf-root">
    <table class="layout section" cellspacing="0" cellpadding="0">
        <tr>
            <td class="text-center" style="padding-bottom:10px;">
                <div class="font-bold" style="font-size:14px;text-transform:uppercase;">{{ $companySettings->company_name ?? config('app.name') }}</div>
            </td>
        </tr>
        <tr>
            <td class="text-center">
                @if($companySettings && $companySettings->company_logo && \Illuminate\Support\Facades\Storage::disk('public')->exists($companySettings->company_logo))
                    <img src="{{ \Illuminate\Support\Facades\Storage::url($companySettings->company_logo) }}" alt="" style="max-width:100px;max-height:56px;"><br>
                @endif
                <span style="font-size:10px;">@if($companySettings->company_address ?? null){{ $companySettings->company_address }}<br>@endif
                @if($companySettings->company_phone ?? null){{ $companySettings->company_phone }}@endif</span>
            </td>
        </tr>
    </table>

    <table class="layout section dash" cellspacing="0" cellpadding="0">
        <tr><td class="text-center font-bold" style="font-size:13px;text-transform:uppercase;">Payment receipt</td></tr>
    </table>

    <table class="layout section row" cellspacing="0" cellpadding="0" width="100%">
        <tr><td>Receipt #</td><td>{{ $payment->payment_number ?? '—' }}</td></tr>
        <tr><td>Date</td><td>{{ ($payment->payment_date ?? now())->format('M d, Y H:i') }}</td></tr>
        <tr><td>Method</td><td>{{ ucfirst(str_replace('_', ' ', (string) ($payment->payment_method ?? '—'))) }}</td></tr>
        @if($payment->customer ?? null)
        <tr><td>Customer</td><td>{{ $payment->customer->name }}</td></tr>
        @endif
    </table>

    @if($payment->invoice ?? null)
    <table class="layout section dash" cellspacing="0" cellpadding="0" width="100%">
        <tr><td colspan="2">Invoice: {{ $payment->invoice->invoice_number }}</td></tr>
    </table>
    @endif

    <table class="layout section row" cellspacing="0" cellpadding="0" width="100%" style="margin-top:10px;">
        <tr style="border-top:1px dashed #000;">
            <td class="font-bold" style="padding-top:8px;">Amount paid</td>
            <td class="font-bold text-right" style="padding-top:8px;font-size:14px;">{{ $payment->currency ?? 'USD' }} {{ number_format($payment->amount ?? 0, 2) }}</td>
        </tr>
    </table>

    @if($payment->transaction_id)
    <table class="layout section row" cellspacing="0" cellpadding="0" width="100%">
        <tr><td>Txn ID</td><td>{{ $payment->transaction_id }}</td></tr>
    </table>
    @endif

    <table class="layout section dash" cellspacing="0" cellpadding="0">
        <tr><td class="text-center" style="font-size:10px;padding-top:12px;">Thank you · retain for your records</td></tr>
    </table>
</div>
</body>
</html>
