<x-shop-layout title="অর্ডার অনুসন্ধানের ফলাফল">
<div class="min-h-screen bg-gray-50 py-8">
    <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
        <!-- Header -->
        <div class="mb-8">
            <div class="flex items-center justify-between">
                <div>
                    <h1 class="text-3xl font-bold text-gray-900">অর্ডার অনুসন্ধানের ফলাফল</h1>
                    <p class="text-gray-600 mt-2">
                        {{ $orders->count() }} টি অর্ডার পাওয়া গেছে: 
                        <span class="font-semibold">{{ $searchType === 'order_number' ? 'অর্ডার নম্বর' : 'ফোন নম্বর' }}: {{ $searchValue }}</span>
                    </p>
                </div>
                <a href="{{ route('order.tracking') }}" 
                   class="bg-gray-100 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-200 transition-colors">
                    নতুন অনুসন্ধান
                </a>
            </div>
        </div>

        <!-- Orders List -->
        <div class="space-y-6">
            @foreach($orders as $order)
            <div class="bg-white rounded-lg shadow-md overflow-hidden">
                <!-- Order Header -->
                <div class="px-6 py-4 bg-gray-50 border-b border-gray-200">
                    <div class="flex items-center justify-between">
                        <div>
                            <h3 class="text-lg font-semibold text-gray-900">
                                অর্ডার #{{ $order->order_number }}
                            </h3>
                            <p class="text-sm text-gray-600">
                                {{ $order->created_at->setTimezone('Asia/Dhaka')->format('M d, Y \a\t g:i A') }} তারিখে করা হয়েছে
                            </p>
                        </div>
                        <div class="text-right">
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium
                                {{ $order->status === 'delivered' ? 'bg-green-100 text-green-800' : 
                                   ($order->status === 'shipped' ? 'bg-blue-100 text-blue-800' : 
                                   ($order->status === 'confirmed' ? 'bg-yellow-100 text-yellow-800' : 
                                   ($order->status === 'cancelled' ? 'bg-red-100 text-red-800' : 'bg-gray-100 text-gray-800'))) }}">
                                {{ ucfirst($order->status) }}
                            </span>
                            <p class="text-lg font-bold text-gray-900 mt-1">৳{{ number_format($order->total_amount, 2) }}</p>
                        </div>
                    </div>
                </div>

                <!-- Order Content -->
                <div class="px-6 py-4">
                    <!-- Customer Info -->
                    @auth
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
                        <div>
                            <h4 class="font-semibold text-gray-900 mb-2">কাস্টমারের তথ্য</h4>
                            <p class="text-gray-600">{{ $order->customer_name }}</p>
                            <p class="text-gray-600">{{ $order->customer_phone }}</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-900 mb-2">ডেলিভারি ঠিকানা</h4>
                            <p class="text-gray-600">{{ $order->customer_address }}</p>
                        </div>
                    </div>
                    @else
                    <div class="mb-4 p-3 bg-yellow-50 border border-yellow-200 rounded-lg">
                        <p class="text-yellow-800 text-sm">
                            <svg class="w-4 h-4 inline mr-1" fill="currentColor" viewBox="0 0 20 20">
                                <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"></path>
                            </svg>
                            কাস্টমারের তথ্য লুকানো আছে। সম্পূর্ণ অর্ডারের তথ্য দেখতে দয়া করে লগ ইন করুন।
                        </p>
                    </div>
                    @endauth

                    <!-- Order Items Preview -->
                    <div class="mb-4">
                        <h4 class="font-semibold text-gray-900 mb-2">পণ্যসমূহ ({{ $order->orderItems->count() }})</h4>
                        <div class="flex flex-wrap gap-2">
                            @foreach($order->orderItems->take(3) as $item)
                                <span class="inline-flex items-center px-2 py-1 bg-gray-100 text-gray-700 text-sm rounded">
                                    {{ $item->product->name }} ({{ $item->quantity }}x)
                                </span>
                            @endforeach
                            @if($order->orderItems->count() > 3)
                                <span class="inline-flex items-center px-2 py-1 bg-blue-100 text-blue-700 text-sm rounded">
                                    +{{ $order->orderItems->count() - 3 }} টি আরও
                                </span>
                            @endif
                        </div>
                    </div>

                    <!-- Order Timeline Preview -->
                    @if($order->status !== 'cancelled')
                    <div class="mb-4">
                        <h4 class="font-semibold text-gray-900 mb-2">অগ্রগতি</h4>
                        <div class="flex items-center space-x-4 text-sm">
                            <div class="flex items-center {{ $order->created_at ? 'text-green-600' : 'text-gray-400' }}">
                                <div class="w-3 h-3 rounded-full {{ $order->created_at ? 'bg-green-600' : 'bg-gray-300' }} mr-2"></div>
                                করা হয়েছে
                            </div>
                            <div class="flex-1 h-px {{ $order->confirmed_at ? 'bg-green-600' : 'bg-gray-300' }}"></div>
                            <div class="flex items-center {{ $order->confirmed_at ? 'text-green-600' : 'text-gray-400' }}">
                                <div class="w-3 h-3 rounded-full {{ $order->confirmed_at ? 'bg-green-600' : 'bg-gray-300' }} mr-2"></div>
                                নিশ্চিত
                            </div>
                            <div class="flex-1 h-px {{ $order->shipped_at ? 'bg-green-600' : 'bg-gray-300' }}"></div>
                            <div class="flex items-center {{ $order->shipped_at ? 'text-green-600' : 'text-gray-400' }}">
                                <div class="w-3 h-3 rounded-full {{ $order->shipped_at ? 'bg-green-600' : 'bg-gray-300' }} mr-2"></div>
                                শিপ করা হয়েছে
                            </div>
                            <div class="flex-1 h-px {{ $order->delivered_at ? 'bg-green-600' : 'bg-gray-300' }}"></div>
                            <div class="flex items-center {{ $order->delivered_at ? 'text-green-600' : 'text-gray-400' }}">
                                <div class="w-3 h-3 rounded-full {{ $order->delivered_at ? 'bg-green-600' : 'bg-gray-300' }} mr-2"></div>
                                ডেলিভার করা হয়েছে
                            </div>
                        </div>
                    </div>
                    @endif

                    <!-- Action Button -->
                    <div class="flex justify-end">
                        @auth
                            <a href="{{ route('order.tracking.details', $order->order_number) }}" 
                               class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors">
                                সম্পূর্ণ বিবরণ দেখুন
                            </a>
                        @else
                            <div class="text-right">
                                <p class="text-sm text-gray-600 mb-2">সম্পূর্ণ বিবরণ দেখতে দয়া করে লগ ইন করুন</p>
                                <div class="space-x-2">
                                    <button onclick="openLoginModal()" 
                                       class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors cursor-pointer">
                                        লগ ইন
                                    </button>
                                    <button onclick="openRegisterModal()" 
                                        class="bg-green-600 text-white px-4 py-2 rounded-lg hover:bg-green-700 transition-colors cursor-pointer">
                                        রেজিস্টার
                                    </button>
                                </div>
                            </div>
                        @endauth
                    </div>
                </div>
            </div>
            @endforeach
        </div>

        <!-- Back to Search -->
        <div class="mt-8 text-center">
            <a href="{{ route('order.tracking') }}" 
               class="inline-flex items-center text-blue-600 hover:text-blue-800">
                <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                </svg>
                অন্য অর্ডার খুঁজুন
            </a>
        </div>
    </div>
</div>
</x-shop-layout>