<x-app-layout title="Lab requests">
    <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <div>
            <h1 class="text-xl font-semibold text-slate-900">Investigation requests</h1>
            <p class="mt-1 text-sm text-slate-500">All laboratory and diagnostic requests</p>
        </div>
        <a href="{{ route('care.lab.queue.index') }}" class="btn-primary">Lab queue</a>
    </div>

    <form method="GET" class="mt-4 flex flex-wrap gap-3 rounded-2xl border border-slate-200 bg-white p-4">
        <select name="status" class="rounded-lg border-slate-300 text-sm">
            <option value="">All statuses</option>
            @foreach ($statuses as $value => $label)
                <option value="{{ $value }}" @selected(request('status') === $value)>{{ $label }}</option>
            @endforeach
        </select>
        <button type="submit" class="btn-primary">Filter</button>
    </form>

    <div class="mt-4 overflow-hidden rounded-2xl border border-slate-200 bg-white">
        <table class="min-w-full text-sm">
            <thead class="bg-slate-50 text-left text-xs uppercase text-slate-500">
                <tr>
                    <th class="px-4 py-3">Patient</th>
                    <th class="px-4 py-3">Test</th>
                    <th class="px-4 py-3">Status</th>
                    <th class="px-4 py-3">Requested</th>
                    <th class="px-4 py-3"></th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-50">
                @forelse ($requests as $item)
                    <tr>
                        <td class="px-4 py-3 font-medium">{{ $item->patient->fullName() }}</td>
                        <td class="px-4 py-3">{{ $item->investigationType->name }}</td>
                        <td class="px-4 py-3">{{ $statuses[$item->status] ?? $item->status }}</td>
                        <td class="px-4 py-3">{{ $item->created_at->format('d M Y') }}</td>
                        <td class="px-4 py-3 text-right"><a href="{{ route('care.lab.requests.show', $item) }}" class="text-sky-600">View</a></td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="px-4 py-8 text-center text-slate-500">No requests found.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $requests->links() }}</div>
</x-app-layout>
