@extends('layouts.app', ['title' => 'Orders | Print Cards'])

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-1">My Orders</h1>
            <p class="text-muted mb-0">Track each order from upload to delivery.</p>
        </div>
        <a href="{{ route('orders.create') }}" class="btn btn-primary">Place New Order</a>
    </div>

    <div class="card card-soft">
        <div class="card-body">
            @if($orders->isEmpty())
                <p class="text-muted mb-0">No orders found yet.</p>
            @else
                <div class="table-responsive">
                    <table class="table align-middle">
                        <thead>
                            <tr>
                                <th>Order</th>
                                <th>Status</th>
                                <th>Payment</th>
                                <th>Total</th>
                                <th>Date</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($orders as $order)
                                <tr>
                                    <td>
                                        <div class="fw-semibold">{{ $order->order_number }}</div>
                                        <div class="small text-muted">{{ $order->items->first()?->item_name }}</div>
                                    </td>
                                    <td><span class="status-pill">{{ ucfirst($order->status) }}</span></td>
                                    <td>{{ ucfirst($order->payment_status) }}</td>
                                    <td>Rs {{ number_format($order->total_amount, 2) }}</td>
                                    <td>{{ $order->created_at->format('d M Y') }}</td>
                                    <td><a href="{{ route('orders.show', $order) }}" class="btn btn-sm btn-outline-primary">Open</a></td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @endif
        </div>
    </div>
@endsection
