@extends('layouts.app')

@section('title', 'Admin - Orders')

@section('content')
<div class="max-w-7xl mx-auto space-y-6">
    <div class="flex justify-between items-center">
        <h1 class="text-3xl font-semibold">Orders Management</h1>
        <a href="{{ route('admin.dashboard') }}" class="text-slate-700 hover:text-slate-900">← Back to Dashboard</a>
    </div>

    <div class="overflow-x-auto rounded-3xl bg-white shadow-sm">
        <table class="min-w-full divide-y divide-slate-200 text-sm">
            <thead class="bg-slate-50 text-slate-700">
                <tr>
                    <th class="px-6 py-4 text-left font-semibold">Order ID</th>
                    <th class="px-6 py-4 text-left font-semibold">Customer</th>
                    <th class="px-6 py-4 text-left font-semibold">Email</th>
                    <th class="px-6 py-4 text-left font-semibold">Total</th>
                    <th class="px-6 py-4 text-left font-semibold">Status</th>
                    <th class="px-6 py-4 text-left font-semibold">Date</th>
                    <th class="px-6 py-4 text-left font-semibold">Action</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-200 bg-white">
                @forelse($orders as $order)
                    <tr>
                        <td class="px-6 py-4 font-semibold">{{ $order->order_number }}</td>
                        <td class="px-6 py-4">{{ $order->user->name ?? $order->customer_name }}</td>
                        <td class="px-6 py-4 text-slate-600">{{ $order->email }}</td>
                        <td class="px-6 py-4 font-semibold">₹{{ number_format($order->total, 2) }}</td>
                        <td class="px-6 py-4">
                            <span class="rounded-full px-3 py-1 text-xs font-semibold
                                @if($order->status === 'Pending') bg-yellow-100 text-yellow-700
                                @elseif($order->status === 'Processing') bg-blue-100 text-blue-700
                                @elseif($order->status === 'Shipped') bg-purple-100 text-purple-700
                                @elseif($order->status === 'Delivered') bg-green-100 text-green-700
                                @elseif($order->status === 'Cancelled') bg-red-100 text-red-700
                                @endif">
                                {{ $order->status }}
                            </span>
                        </td>
                        <td class="px-6 py-4">{{ $order->created_at->format('M d, Y') }}</td>
                        <td class="px-6 py-4">
                            <a href="{{ route('admin.orders.show', $order) }}" class="text-slate-700 hover:text-slate-900 font-semibold">View</a>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="7" class="px-6 py-12 text-center text-slate-600">No orders found</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    {{ $orders->links() }}
</div>
@endsection
