@extends('layout')
@section('title', 'Device Health')
@section('content')
<div class="page-header"><h1>Device Health</h1></div>

<div class="card">
    <div class="table-wrap">
    <table>
        <thead>
            <tr><th>Site</th><th>Device</th><th>Status</th><th>Last seen</th><th>Camera</th><th>Queue depth</th><th>Agent version</th></tr>
        </thead>
        <tbody>
        @forelse($devices as $device)
            <tr>
                <td>{{ $device->site->name }}</td>
                <td>{{ $device->name }}</td>
                <td>
                    @if($device->isOnline())
                        <span class="badge badge-green">Online</span>
                    @else
                        <span class="badge badge-red">Offline</span>
                    @endif
                </td>
                <td>{{ $device->last_seen?->format('Y-m-d H:i:s') ?? 'Never' }}</td>
                <td>
                    @if(is_null($device->camera_ok))
                        <span class="badge badge-gray">Unknown</span>
                    @elseif($device->camera_ok)
                        <span class="badge badge-green">OK</span>
                    @else
                        <span class="badge badge-red">Fault</span>
                    @endif
                </td>
                <td>{{ $device->last_queue_depth ?? '—' }}</td>
                <td>{{ $device->agent_version ?? '—' }}</td>
            </tr>
        @empty
            <tr><td colspan="7" class="empty-state">No devices registered.</td></tr>
        @endforelse
        </tbody>
    </table>
    </div>
</div>
@endsection
