<x-app-layout title="Departments">
    <div class="space-y-6">
        <x-care.page-hero
            badge="Outpatient · Lab · Pharmacy · More"
            title="Departments"
            description="Define clinical and support departments within each branch to organize care delivery and staffing."
            :stats="[
                ['value' => number_format($heroStats['total']), 'label' => 'Departments'],
                ['value' => number_format($heroStats['active']), 'label' => 'Active'],
                ['value' => number_format($heroStats['branches']), 'label' => 'Branches'],
            ]">
            <x-slot name="actions">
                <a href="{{ route('care.care-units.index') }}" class="btn-secondary">Care units</a>
                @if ($canManage ?? false)
                    <a href="{{ route('care.departments.create') }}" class="btn-primary">Add department</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">Type</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 ($departments as $department)
                        <tr>
                            <td class="px-4 py-3 font-medium">{{ $department->name }}</td>
                            <td class="px-4 py-3">{{ $types[$department->type] ?? $department->type }}</td>
                            <td class="px-4 py-3">{{ $department->branch?->name }}</td>
                            <td class="px-4 py-3 text-right">
                                @if ($canManage ?? false)
                                    <a href="{{ route('care.departments.edit', $department) }}" class="text-sky-600">Edit</a>
                                @endif
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="4" class="px-4 py-6 text-center text-slate-500">No departments yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</x-app-layout>
