<x-app-layout title="Prescriptions">
    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-xl font-semibold text-slate-900">Prescriptions</h1>
            <p class="mt-1 text-sm text-slate-500">All prescriptions across the facility</p>
        </div>
        <a href="{{ route('care.prescriptions.queue') }}" class="btn-primary">Pharmacy queue</a>
    </div>
    <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">Items</th><th class="px-4 py-3">Status</th><th class="px-4 py-3">Date</th><th></th></tr>
            </thead>
            <tbody class="divide-y divide-slate-50">
                @forelse ($prescriptions as $rx)
                    <tr>
                        <td class="px-4 py-3 font-medium">{{ $rx->patient->fullName() }}</td>
                        <td class="px-4 py-3">{{ $rx->items->pluck('name')->join(', ') }}</td>
                        <td class="px-4 py-3">{{ $statuses[$rx->status] ?? $rx->status }}</td>
                        <td class="px-4 py-3">{{ $rx->created_at->format('d M Y') }}</td>
                        <td class="px-4 py-3 text-right"><a href="{{ route('care.prescriptions.show', $rx) }}" class="text-sky-600">View</a></td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="px-4 py-8 text-center text-slate-500">No prescriptions.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $prescriptions->links() }}</div>
</x-app-layout>
