@extends('layouts.admin')

@section('title', 'Pickup Requests')

@section('content')
<div class="admin-page-header">
    <h1>Pickup Requests</h1>
    <a href="{{ route('admin.pickup-requests.create') }}" class="admin-btn-primary">
        <i class="bi bi-plus"></i> Create Pickup Request
    </a>
</div>

<!-- Filters -->
<div class="admin-card mb-3">
    <div class="card-body">
        <form method="GET" action="{{ route('admin.pickup-requests.index') }}" class="row g-3 align-items-end justify-content-end">
            <div class="col-md-4">
                <label class="admin-form-label">Search</label>
                <input type="text"
                       name="search"
                       class="admin-form-control form-control"
                       placeholder="Search by location or pickup ID"
                       value="{{ request('search') }}">
            </div>
            <div class="col-md-3">
                <label class="admin-form-label">Pickup Date</label>
                <input type="date"
                       name="pickup_date"
                       class="admin-form-control form-control"
                       value="{{ request('pickup_date') }}">
            </div>
            <div class="col-md-3">
                <button type="submit" class="admin-btn-primary w-100" style="margin-top: 28px;">
                    <i class="bi bi-search"></i> Filter
                </button>
            </div>
            @if(request()->hasAny(['search', 'pickup_date']))
            <div class="col-md-1">
                <a href="{{ route('admin.pickup-requests.index') }}" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-counterclockwise"></i> 
                </a>
            </div>
            @endif
        </form>
    </div>
</div>

<div class="admin-card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="admin-table table table-hover">
                <thead>
                    <tr>
                        <th style="font-weight: 700; text-align: left;">Pickup ID</th>
                        <th style="font-weight: 700; text-align: left;">Location</th>
                        <th style="font-weight: 700; text-align: center;">Pickup Date</th>
                        <th style="font-weight: 700; text-align: center;">Pickup Time</th>
                        <th style="font-weight: 700; text-align: center;">Package Count</th>
                        <th style="font-weight: 700; text-align: center;">Created At</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($pickups as $pickup)
                        <tr class="table-row-hover">
                            <td>
                                @if($pickup->pickup_id)
                                    <code class="text-primary">{{ $pickup->pickup_id }}</code>
                                @else
                                    <span class="text-muted">-</span>
                                @endif
                            </td>
                            <td>
                                <span style="font-weight: 500;">{{ $pickup->pickup_location }}</span>
                            </td>
                            <td style="text-align: center;">
                                {{ $pickup->pickup_date ? $pickup->pickup_date->format('Y-m-d') : '-' }}
                            </td>
                            <td style="text-align: center;">
                                {{ $pickup->pickup_time ? date('H:i', strtotime($pickup->pickup_time)) : '-' }}
                            </td>
                            <td style="text-align: center;">
                                <span class="badge bg-info">{{ $pickup->expected_package_count }}</span>
                            </td>
                            <td style="text-align: center;">
                                <small class="text-muted">{{ $pickup->created_at->format('Y-m-d H:i') }}</small>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="text-center py-5">
                                <div class="admin-empty-state">
                                    <i class="bi bi-box-seam"></i>
                                    <h3>No Pickup Requests Found</h3>
                                    <p>Get started by creating your first pickup request.</p>
                                    <a href="{{ route('admin.pickup-requests.create') }}" class="admin-btn-primary">
                                        <i class="bi bi-plus"></i> Create Pickup Request
                                    </a>
                                </div>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <!-- Pagination -->
        <div class="pagination-wrapper mt-4">
            <div class="d-flex justify-content-end align-items-center gap-3 flex-wrap">
                <div class="pagination-info-text">
                    Showing <strong>{{ $pickups->firstItem() ?? 0 }}</strong>–<strong>{{ $pickups->lastItem() ?? 0 }}</strong> 
                    of <strong>{{ $pickups->total() }}</strong> pickup requests
                </div>
                @if($pickups->hasPages())
                    <div class="pagination-controls">
                        {{ $pickups->links('vendor.pagination.admin-categories') }}
                    </div>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection

