@extends('account.layout')
@php
    $badgeColors = [
        'success' => 'bg-green-100 text-green-800',
        'danger' => 'bg-red-100 text-red-800',
        'warning' => 'bg-yellow-100 text-yellow-800',
        'info' => 'bg-blue-100 text-blue-800',
        'secondary' => 'bg-gray-100 text-gray-800',
    ];
@endphp
@section('account-content')
<div>
    <div class="flex flex-wrap items-center justify-between gap-4 mb-6">
        <h1 class="text-2xl font-bold">Order #{{ $order->order_number }}</h1>
        <a href="{{ route('account.orders') }}" class="inline-flex items-center gap-1.5 px-4 py-2 rounded-lg font-medium transition-colors border border-gray-300 text-gray-700 hover:bg-gray-100">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/></svg>
            Back to Orders
        </a>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <div class="lg:col-span-2 space-y-6">
            <div class="bg-white rounded-xl shadow-sm border border-gray-100">
                <div class="p-6">
                    <h5 class="text-lg font-semibold mb-4">Order Items</h5>
                    <div class="overflow-x-auto">
                        <table class="w-full border-collapse">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Product</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Quantity</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Price</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($order->items as $item)
                                <tr class="hover:bg-gray-50">
                                    <td class="px-4 py-3 border-b border-gray-200">
                                        <div class="flex items-center gap-3">
                                            @if($item->product->images && $item->product->images->count() > 0)
                                                <img src="{{ asset('storage/' . $item->product->images->first()->path) }}" 
                                                    alt="{{ $item->product->name }}" 
                                                    class="w-12 h-12 object-cover rounded-lg shrink-0">
                                            @else
                                                <img src="{{ asset('images/no-image.png') }}" 
                                                    alt="No Image Available" 
                                                    class="w-12 h-12 object-cover rounded-lg shrink-0">
                                            @endif
                                            <p class="text-sm font-medium">{{ $item->product->name }}</p>
                                        </div>
                                    </td>
                                    <td class="px-4 py-3 text-sm text-gray-700 border-b border-gray-200">{{ $item->quantity }}</td>
                                    <td class="px-4 py-3 text-sm text-gray-700 border-b border-gray-200">${{ number_format($item->price, 2) }}</td>
                                    <td class="px-4 py-3 text-sm text-gray-700 border-b border-gray-200 font-medium">${{ number_format($item->total, 2) }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-sm border border-gray-100">
                <div class="p-6">
                    <h5 class="text-lg font-semibold mb-4">Order Status</h5>
                    <div class="flex items-center gap-3 mb-3">
                        <span class="inline-block text-xs font-medium px-2 py-1 rounded-full {{ $badgeColors[$order->status_color] ?? 'bg-gray-100 text-gray-800' }}">{{ $order->status }}</span>
                        <span class="text-sm text-gray-500">{{ $order->created_at->format('F d, Y h:i A') }}</span>
                    </div>
                    @if($order->tracking_number)
                    <div class="bg-blue-50 border border-blue-200 text-blue-700 px-4 py-3 rounded-lg text-sm flex items-center gap-2">
                        <svg class="w-4 h-4 shrink-0" 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 1v10l2-1 2 1 2-1 2 1 2-1 2 1V6"/></svg>
                        Tracking Number: {{ $order->tracking_number }}
                    </div>
                    @endif
                </div>
            </div>
        </div>

        <div class="space-y-6">
            <div class="bg-white rounded-xl shadow-sm border border-gray-100">
                <div class="p-6">
                    <h5 class="text-lg font-semibold mb-4">Order Summary</h5>
                    <div class="space-y-2">
                        <div class="flex justify-between text-sm">
                            <span class="text-gray-600">Subtotal</span>
                            <span>${{ number_format($order->subtotal, 2) }}</span>
                        </div>
                        <div class="flex justify-between text-sm">
                            <span class="text-gray-600">Tax</span>
                            <span>${{ number_format($order->tax, 2) }}</span>
                        </div>
                        @if($order->shipping_cost)
                        <div class="flex justify-between text-sm">
                            <span class="text-gray-600">Shipping</span>
                            <span>${{ number_format($order->shipping_cost, 2) }}</span>
                        </div>
                        @endif
                        <hr class="border-gray-200">
                        <div class="flex justify-between font-semibold">
                            <span>Total</span>
                            <span>${{ number_format($order->total, 2) }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
