@php($dir = app()->getLocale() === 'ar' ? 'rtl' : 'ltr')
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}" dir="{{ $dir }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ __('accounts.partners.delivery_receipt_title') }}</title>
    <link href="{{ asset('css/accounts.css') }}" rel="stylesheet">
    <style>
        body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif; }
        .print-container { max-width: 900px; margin: 0 auto; padding: 24px; }
        .header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
        .title { font-weight: 800; font-size: 20px; }
        .meta { color: #6c757d; font-size: 12px; line-height: 1.6; text-align: end; }
        table { width: 100%; border-collapse: collapse; margin-top: 12px; }
        th, td { border: 1px solid #dee2e6; padding: 10px; font-size: 12px; vertical-align: top; }
        th { background: #f8f9fa; text-align: start; width: 28%; }
        .fw-bold { font-weight: 700; }
        .text-end { text-align: end; }
        .muted { color: #6c757d; }
        .signatures { margin-top: 28px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
        .sig-box { border: 1px solid #dee2e6; padding: 14px; }
        .sig-title { font-weight: 700; margin-bottom: 18px; }
        .sig-line { border-bottom: 1px solid #212529; height: 28px; margin-top: 22px; }
        .sig-hint { margin-top: 8px; font-size: 12px; color: #6c757d; }
        @media print {
            .no-print { display: none !important; }
            body { background: #fff !important; }
        }
    </style>
</head>
<body>
    <div class="print-container">
        <div class="header">
            <div>
                <div class="title">{{ __('accounts.partners.delivery_receipt_title') }}</div>
                <div class="muted">{{ __('accounts.partners.owner_box') }}</div>
            </div>
            <div class="meta" dir="ltr">
                <div>{{ __('accounts.partners.receipt_no') }}: #{{ (int) $transaction->id }}</div>
                <div>{{ __('accounts.reserve_box.transaction_date') }}: {{ $transaction->transaction_date?->format('Y-m-d') ?? '—' }}</div>
                <div>{{ __('accounts.reserve_box.transaction_time') }}: {{ $transaction->created_at?->translatedFormat('h:i A') ?? '—' }}</div>
                <div>{{ __('accounts.reserve_box.created_by') }}: {{ $transaction->creator?->name ?? '—' }}</div>
                <div>{{ __('accounts.partners.printed_at') }}: {{ now()->translatedFormat('Y-m-d h:i A') }}</div>
                <div>{{ __('accounts.partners.printed_by') }}: {{ $printedBy?->name ?? '—' }}</div>
            </div>
        </div>

        <table>
            <tr>
                <th>{{ __('accounts.reserve_box.from_box') }}</th>
                <td>
                    @php($fromLabels = [])
                    @if((int) ($transaction->cash_amount ?? 0) > 0)
                        @php($fromLabels[] = __('accounts.reserve_box.boxes.reserve_cash'))
                    @endif
                    @if((int) ($transaction->online_amount ?? 0) > 0)
                        @php($fromLabels[] = __('accounts.reserve_box.boxes.reserve_online'))
                    @endif
                    <span class="fw-bold">{{ implode(' + ', $fromLabels) ?: '—' }}</span>
                </td>
            </tr>
            <tr>
                <th>{{ __('accounts.reserve_box.cash_amount') }}</th>
                <td class="fw-bold">{{ number_format((int) ($transaction->cash_amount ?? 0), 0) }}</td>
            </tr>
            <tr>
                <th>{{ __('accounts.reserve_box.online_amount') }}</th>
                <td class="fw-bold">{{ number_format((int) ($transaction->online_amount ?? 0), 0) }}</td>
            </tr>
            <tr>
                <th>{{ __('accounts.partners.total_amount') }}</th>
                <td class="fw-bold">{{ number_format((int) ($transaction->amount ?? 0), 0) }}</td>
            </tr>
            <tr>
                <th>{{ __('accounts.reserve_box.notes') }}</th>
                <td class="muted">{{ $transaction->notes ?? '—' }}</td>
            </tr>
        </table>

        <div class="signatures">
            <div class="sig-box">
                <div class="sig-title">{{ __('accounts.partners.accountant_signature') }}</div>
                <div class="sig-line"></div>
                <div class="sig-hint">{{ __('accounts.partners.signature_hint') }}</div>
            </div>
            <div class="sig-box">
                <div class="sig-title">{{ __('accounts.partners.owner_signature') }}</div>
                <div class="sig-line"></div>
                <div class="sig-hint">{{ __('accounts.partners.signature_hint') }}</div>
            </div>
        </div>
    </div>
    <script>window.print()</script>
</body>
</html>
