<!DOCTYPE html>
<html dir="rtl" lang="ar">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>إيصال دفع {{ $payment->reference ?? $payment->uuid }}</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap" rel="stylesheet">
    <style>
        body { font-family: 'Cairo', sans-serif; }
        @media print {
            .no-print { display: none; }
            body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen py-8">
    <div class="max-w-md mx-auto bg-white shadow-lg rounded-lg overflow-hidden">
        {{-- Header --}}
        <div class="bg-green-700 text-white px-6 py-5 text-center">
            <h1 class="text-xl font-bold">إيصال دفع</h1>
            <p class="text-green-100 mt-1 text-sm">{{ $payment->reference ?? $payment->uuid }}</p>
        </div>

        {{-- Payment Details --}}
        <div class="px-6 py-6 space-y-4">
            {{-- Amount --}}
            <div class="text-center py-4 border-b border-gray-200">
                <p class="text-sm text-gray-500 mb-1">المبلغ المدفوع</p>
                <p class="text-3xl font-bold text-gray-800" dir="ltr">{{ number_format($payment->amount / 100, 2) }} ج.م</p>
            </div>

            {{-- Details Grid --}}
            <div class="space-y-3 py-2">
                <div class="flex justify-between items-center">
                    <span class="text-gray-500 text-sm">طريقة الدفع</span>
                    @php
                        $methodLabels = [
                            'cash' => 'نقدي',
                            'card' => 'بطاقة',
                            'bank_transfer' => 'تحويل بنكي',
                            'wallet' => 'محفظة',
                            'online' => 'إلكتروني',
                            'cheque' => 'شيك',
                            'other' => 'أخرى',
                        ];
                        $methodValue = $payment->method?->value ?? $payment->method ?? '';
                    @endphp
                    <span class="font-medium text-gray-800">{{ $methodLabels[$methodValue] ?? $methodValue }}</span>
                </div>

                <div class="flex justify-between items-center">
                    <span class="text-gray-500 text-sm">تاريخ الدفع</span>
                    <span class="font-medium text-gray-800">{{ $payment->payment_date?->format('Y-m-d') ?? $payment->created_at?->format('Y-m-d') }}</span>
                </div>

                @if($payment->invoice)
                    <div class="flex justify-between items-center">
                        <span class="text-gray-500 text-sm">رقم الفاتورة</span>
                        <span class="font-medium text-gray-800">{{ $payment->invoice->number }}</span>
                    </div>
                @endif

                <div class="flex justify-between items-center">
                    <span class="text-gray-500 text-sm">الدافع</span>
                    <span class="font-medium text-gray-800">
                        {{ $payment->invoice?->contact_name ?? $payment->invoice?->billable?->person?->name_ar ?? $payment->invoice?->billable?->person?->name ?? '-' }}
                    </span>
                </div>

                @if($payment->creator)
                    <div class="flex justify-between items-center">
                        <span class="text-gray-500 text-sm">استلم بواسطة</span>
                        <span class="font-medium text-gray-800">{{ $payment->creator->name }}</span>
                    </div>
                @endif
            </div>

            {{-- Status --}}
            @php
                $statusLabels = [
                    'pending' => 'معلق',
                    'confirmed' => 'مؤكد',
                    'failed' => 'فاشل',
                    'cancelled' => 'ملغى',
                    'refunded' => 'مسترد',
                ];
                $statusColors = [
                    'pending' => 'bg-yellow-100 text-yellow-700',
                    'confirmed' => 'bg-green-100 text-green-700',
                    'failed' => 'bg-red-100 text-red-700',
                    'cancelled' => 'bg-gray-100 text-gray-500',
                    'refunded' => 'bg-purple-100 text-purple-700',
                ];
                $statusValue = $payment->status?->value ?? $payment->status ?? '';
            @endphp
            <div class="text-center pt-4 border-t border-gray-200">
                <span class="inline-block px-4 py-1.5 rounded-full text-sm font-semibold {{ $statusColors[$statusValue] ?? 'bg-gray-100 text-gray-700' }}">
                    {{ $statusLabels[$statusValue] ?? $statusValue }}
                </span>
            </div>
        </div>

        {{-- Notes --}}
        @if($payment->notes)
            <div class="px-6 py-3 border-t border-gray-200">
                <p class="text-sm text-gray-500">ملاحظات:</p>
                <p class="text-gray-700 text-sm mt-1">{{ $payment->notes }}</p>
            </div>
        @endif

        {{-- Footer --}}
        <div class="px-6 py-4 bg-gray-100 text-center">
            <p class="text-xs text-gray-500">تم إنشاء هذا المستند إلكترونياً</p>
        </div>
    </div>

    {{-- Print Button --}}
    <div class="max-w-md mx-auto mt-4 text-center no-print">
        <button onclick="window.print()" class="bg-green-600 text-white px-6 py-2 rounded-lg hover:bg-green-700 transition">
            طباعة
        </button>
    </div>
</body>
</html>
