<!DOCTYPE html>
<html dir="rtl" lang="ar">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>إيصال مبيعات {{ $transaction->receipt_number }}</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-indigo-700 text-white px-6 py-5 text-center">
            <h1 class="text-xl font-bold">إيصال مبيعات</h1>
            <p class="text-indigo-100 mt-1 text-sm">{{ $transaction->receipt_number }}</p>
        </div>

        {{-- Transaction Info --}}
        <div class="px-6 py-4 border-b border-gray-200">
            <div class="flex justify-between items-center text-sm">
                <span class="text-gray-500">التاريخ</span>
                <span class="font-medium text-gray-800">{{ $transaction->processed_at?->format('Y-m-d H:i') ?? $transaction->created_at?->format('Y-m-d H:i') }}</span>
            </div>
            @if($transaction->participant?->person)
                <div class="flex justify-between items-center text-sm mt-2">
                    <span class="text-gray-500">العميل</span>
                    <span class="font-medium text-gray-800">{{ $transaction->participant->person->name_ar ?? $transaction->participant->person->name ?? '-' }}</span>
                </div>
            @endif
        </div>

        {{-- Items --}}
        <div class="px-6 py-4">
            <table class="w-full">
                <thead>
                    <tr class="border-b border-gray-200">
                        <th class="text-start py-2 text-xs font-semibold text-gray-500">الصنف</th>
                        <th class="text-center py-2 text-xs font-semibold text-gray-500">الكمية</th>
                        <th class="text-start py-2 text-xs font-semibold text-gray-500">السعر</th>
                        <th class="text-start py-2 text-xs font-semibold text-gray-500">الإجمالي</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($transaction->items as $item)
                        <tr class="border-b border-gray-50">
                            <td class="py-2 text-sm text-gray-800">{{ $item->item_name_ar ?? '-' }}</td>
                            <td class="py-2 text-sm text-center text-gray-600">{{ $item->quantity }}</td>
                            <td class="py-2 text-sm text-gray-600" dir="ltr">{{ number_format($item->unit_price / 100, 2) }}</td>
                            <td class="py-2 text-sm font-medium text-gray-800" dir="ltr">{{ number_format($item->line_total / 100, 2) }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        {{-- Totals --}}
        <div class="px-6 py-4 bg-gray-50 border-t border-gray-200 space-y-2">
            <div class="flex justify-between text-sm text-gray-600">
                <span>المجموع الفرعي</span>
                <span dir="ltr">{{ number_format($transaction->subtotal / 100, 2) }} ج.م</span>
            </div>
            @if($transaction->discount_amount > 0)
                <div class="flex justify-between text-sm text-green-600">
                    <span>الخصم</span>
                    <span dir="ltr">- {{ number_format($transaction->discount_amount / 100, 2) }} ج.م</span>
                </div>
            @endif
            @if($transaction->tax_amount > 0)
                <div class="flex justify-between text-sm text-gray-600">
                    <span>الضريبة</span>
                    <span dir="ltr">{{ number_format($transaction->tax_amount / 100, 2) }} ج.م</span>
                </div>
            @endif
            <div class="flex justify-between font-bold text-lg text-gray-800 border-t border-gray-300 pt-2">
                <span>الإجمالي</span>
                <span dir="ltr">{{ number_format($transaction->total_amount / 100, 2) }} ج.م</span>
            </div>

            {{-- Payment Method --}}
            @php
                $posMethodLabels = [
                    'cash' => 'نقدي',
                    'card' => 'بطاقة',
                    'wallet' => 'محفظة',
                    'split' => 'مقسم',
                ];
                $posMethodValue = $transaction->payment_method?->value ?? $transaction->payment_method ?? '';
            @endphp
            <div class="flex justify-between text-sm text-gray-600 pt-1">
                <span>طريقة الدفع</span>
                <span class="font-medium">{{ $posMethodLabels[$posMethodValue] ?? $posMethodValue }}</span>
            </div>
        </div>

        {{-- Cashier --}}
        @if($transaction->processedBy)
            <div class="px-6 py-3 border-t border-gray-200">
                <div class="flex justify-between items-center text-sm">
                    <span class="text-gray-500">الكاشير</span>
                    <span class="text-gray-700">{{ $transaction->processedBy->name }}</span>
                </div>
            </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-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700 transition">
            طباعة
        </button>
    </div>
</body>
</html>
