<x-app-layout title="Displays">
    <div class="space-y-6">
        <x-care.page-hero
            badge="Waiting areas · Voice · Ticket calls"
            title="Display screens"
            description="Waiting-area screens and voice announcements so patients see called tickets and hear when their number is up."
            :stats="[
                ['value' => number_format($heroStats['total']), 'label' => 'Displays'],
                ['value' => number_format($heroStats['active']), 'label' => 'Active'],
                ['value' => number_format($heroStats['branches']), 'label' => 'Branches'],
            ]">
            @if ($canManage)
                <x-slot name="actions">
                    <a href="{{ route('care.displays.create') }}" class="btn-primary">New display</a>
                </x-slot>
            @endif
        </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">Layout</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 ($screens as $screen)
                        <tr>
                            <td class="px-4 py-3 font-medium text-slate-900">
                                <a href="{{ route('care.displays.show', $screen) }}" class="hover:text-indigo-600">{{ $screen->name }}</a>
                            </td>
                            <td class="px-4 py-3 text-slate-600">{{ config('care.display_layouts.'.$screen->layout, $screen->layout) }}</td>
                            <td class="px-4 py-3 text-slate-600">{{ $screen->branch?->name ?? '—' }}</td>
                            <td class="px-4 py-3 text-right">
                                <a href="{{ route('care.display.public', $screen->access_token) }}" target="_blank" rel="noopener" class="text-sky-600 hover:text-sky-700">Open display</a>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="4" class="px-4 py-8 text-center text-slate-500">
                                No display screens yet.
                                @if ($canManage)
                                    <a href="{{ route('care.displays.create') }}" class="ml-1 text-indigo-600 hover:text-indigo-800">Create your first display</a>
                                @endif
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
            @if ($screens->hasPages())
                <div class="border-t border-slate-100 px-5 py-3">{{ $screens->links() }}</div>
            @endif
        </div>
    </div>
</x-app-layout>
