<x-app-layout title="Care units">
    <div class="space-y-6">
        <x-care.page-hero
            badge="Inpatient · Clinics · Float pool"
            title="Care units"
            description="Units under departments — wards, clinics, theatres, and float pools. Staff are assigned to units with effective dates, not permanently bound to a ward."
            :stats="[
                ['value' => number_format($heroStats['total']), 'label' => 'Units'],
                ['value' => number_format($heroStats['inpatient']), 'label' => 'Inpatient'],
                ['value' => number_format($heroStats['float']), 'label' => 'Float pools'],
                ['value' => number_format($heroStats['active']), 'label' => 'Active'],
            ]">
            <x-slot name="actions">
                @if ($canManage ?? false)
                    <a href="{{ route('care.care-units.create') }}" class="btn-primary">Add care unit</a>
                @endif
            </x-slot>
        </x-care.page-hero>

        <div class="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">Name</th>
                        <th class="px-4 py-3">Kind</th>
                        <th class="px-4 py-3">Department</th>
                        <th class="px-4 py-3">Branch</th>
                        <th class="px-4 py-3"></th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-50">
                    @forelse ($units as $unit)
                        <tr class="{{ $unit->is_active ? '' : 'opacity-60' }}">
                            <td class="px-4 py-3 font-medium">
                                {{ $unit->name }}
                                @if ($unit->code)
                                    <span class="ml-1 text-xs text-slate-400">{{ $unit->code }}</span>
                                @endif
                            </td>
                            <td class="px-4 py-3">{{ $kinds[$unit->kind] ?? $unit->kind }}</td>
                            <td class="px-4 py-3">{{ $unit->department?->name }}</td>
                            <td class="px-4 py-3">{{ $unit->department?->branch?->name }}</td>
                            <td class="px-4 py-3 text-right">
                                <a href="{{ route('care.care-units.show', $unit) }}" class="text-sky-600">Open</a>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="5" class="px-4 py-6 text-center text-slate-500">No care units yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</x-app-layout>
