<div>
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8">
        <div>
            <h1 class="text-2xl font-bold text-gray-800">طلباتي</h1>
            <p class="text-sm text-gray-500 mt-1">تتبع جميع طلباتك ومعرفة حالتها</p>
        </div>
        <select wire:model.live="statusFilter"
                class="px-4 py-2.5 rounded-xl border border-gray-200 focus:border-emerald-500 outline-none text-sm">
            <option value="">جميع الحالات</option>
            @foreach($statusLabels as $key => $label)
                <option value="{{ $key }}">{{ $label }}</option>
            @endforeach
        </select>
    </div>

    @if($orders->isEmpty())
        <div class="bg-white rounded-2xl border border-gray-200 p-12 text-center">
            <svg class="w-16 h-16 mx-auto text-gray-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/></svg>
            <p class="text-gray-500 mb-4">لا توجد طلبات</p>
            <a href="{{ route('merchant.products') }}" class="inline-block bg-emerald-600 hover:bg-emerald-700 text-white font-medium px-6 py-2.5 rounded-xl transition">
                ابدأ التسوق
            </a>
        </div>
    @else
        <div class="space-y-3">
            @foreach($orders as $order)
                <a href="{{ route('merchant.orders.show', $order) }}"
                   class="block bg-white rounded-2xl border border-gray-200 p-5 hover:shadow-md hover:border-emerald-200 transition">
                    <div class="flex items-center justify-between">
                        <div class="flex items-center gap-4">
                            <div class="w-12 h-12 rounded-xl flex items-center justify-center
                                @switch($order->status)
                                    @case('delivered') bg-emerald-100 @break
                                    @case('returned') bg-red-100 @break
                                    @case('shipping') bg-blue-100 @break
                                    @default bg-amber-100
                                @endswitch">
                                @switch($order->status)
                                    @case('delivered')
                                        <svg class="w-6 h-6 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
                                        @break
                                    @case('returned')
                                        <svg class="w-6 h-6 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"/></svg>
                                        @break
                                    @case('shipping')
                                        <svg class="w-6 h-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16V6a1 1 0 00-1-1H4a1 1 0 00-1 1v10a1 1 0 001 1h1m8-1a1 1 0 01-1 1H9m4-1V8a1 1 0 011-1h2.586a1 1 0 01.707.293l3.414 3.414a1 1 0 01.293.707V16a1 1 0 01-1 1h-1m-6-1a1 1 0 001 1h1M5 17a2 2 0 104 0m-4 0a2 2 0 114 0m6 0a2 2 0 104 0m-4 0a2 2 0 114 0"/></svg>
                                        @break
                                    @default
                                        <svg class="w-6 h-6 text-amber-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                                @endswitch
                            </div>
                            <div>
                                <div class="flex items-center gap-2">
                                    <p class="font-bold text-gray-800">طلب #{{ $order->id }}</p>
                                    <span class="text-xs px-2.5 py-0.5 rounded-full font-medium
                                        @switch($order->status)
                                            @case('delivered') bg-emerald-100 text-emerald-700 @break
                                            @case('returned') bg-red-100 text-red-700 @break
                                            @case('shipping') bg-blue-100 text-blue-700 @break
                                            @case('processing') bg-purple-100 text-purple-700 @break
                                            @default bg-amber-100 text-amber-700
                                        @endswitch">
                                        {{ $statusLabels[$order->status] ?? $order->status }}
                                    </span>
                                </div>
                                <div class="flex items-center gap-3 text-xs text-gray-500 mt-1">
                                    <span>{{ $order->created_at->diffForHumans() }}</span>
                                    <span>·</span>
                                    <span>{{ $order->items_count }} عنصر</span>
                                    @if($order->points_earned > 0)
                                        <span>·</span>
                                        <span class="text-emerald-600">+{{ $order->points_earned }} نقطة</span>
                                    @endif
                                </div>
                            </div>
                        </div>
                        <div class="text-left">
                            <p class="text-lg font-bold text-gray-800">{{ number_format($order->total, 2) }} ج.م</p>
                            @if($order->discount_from_points > 0)
                                <p class="text-xs text-amber-600">خصم نقاط: {{ number_format($order->discount_from_points, 2) }} ج.م</p>
                            @endif
                        </div>
                    </div>
                </a>
            @endforeach
        </div>
    @endif
</div>
