@extends('backend.layout.app')

@section('content')
<div class="container">
    <div class="container-header">
        <h1>{{ $title }}</h1>
    </div>

    <div class="card table-card">
        <div class="table-header">
            <form method="get" action="{{ route('backend.account-orders.index') }}" class="table-search-form">
                <div class="table-search">
                    <input type="text" name="search" class="search-input" placeholder="Search by user email or name..." value="{{ $search ?? '' }}">
                    <i class="las la-search"></i>
                </div>
                <button type="submit" class="btn btn-secondary search-btn">Search</button>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>User</th>
                        <th>Amount</th>
                        <th>Date</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($orders as $o)
                    <tr>
                        <td>{{ $orders->firstItem() + $loop->index }}</td>
                        <td>{{ $o->user->email ?? '-' }} ({{ $o->user->fname ?? '' }} {{ $o->user->lname ?? '' }})</td>
                        <td>{{ number_format($o->total_amount, 2) }}</td>
                        <td>{{ $o->created_at->format('Y-m-d H:i') }}</td>
                        <td>
                            <a href="{{ route('backend.account-orders.show', $o->id) }}" class="btn btn-sm btn-outline">View</a>
                        </td>
                    </tr>
                    @empty
                    <tr><td colspan="5" class="text-center">No orders yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="pagination-wrapper">
            {{ $orders->links('vendor.pagination.default') }}
        </div>
    </div>
</div>
@endsection
