@php /** @var \Illuminate\Support\Collection $devices */ $statusPill = [ 'connected' => [ 'bg' => 'bg-wa-mint', 'text' => 'text-wa-deep', 'border' => '', 'dot' => 'bg-wa-green', 'label' => 'Connected', ], 'disconnected' => [ 'bg' => 'bg-paper-50', 'text' => 'text-ink-500', 'border' => '', 'dot' => 'bg-paper-200', 'label' => 'Disconnected', ], 'needs_pair' => [ 'bg' => 'bg-accent-amber/15', 'text' => 'text-[#7B5A14]', 'border' => 'border border-accent-amber/40', 'dot' => 'bg-accent-amber', 'label' => 'Needs re-pair', ], 'failed' => [ 'bg' => 'bg-accent-coral/15', 'text' => 'text-[#A1431F]', 'border' => 'border border-accent-coral/40', 'dot' => 'bg-accent-coral', 'label' => 'Failed', ], ]; // Rotating accent palette for the device icon avatar — picks a // colour per device id so the same row paints the same swatch // across reloads. Mirrors the four swatches in the mockup // (mint / blue / purple / paper). $accentPalette = [ ['bg' => 'bg-wa-mint', 'text' => 'text-wa-deep'], ['bg' => 'bg-[#D9E5F2]', 'text' => 'text-[#13478A]'], ['bg' => 'bg-[#F3E9FF]', 'text' => 'text-[#5B3D8A]'], ['bg' => 'bg-paper-100', 'text' => 'text-ink-700'], ]; @endphp @forelse ($devices as $d) @php $pill = $statusPill[$d->status] ?? $statusPill['disconnected']; $active = (bool) $d->active; $accent = $d->status === 'connected' ? $accentPalette[$d->id % 3] // connected rows: rotate among the three colourful swatches : $accentPalette[3]; // disconnected/failed/needs_pair: neutral paper swatch // Resolve the assigned user — eager-loaded by the controller // when possible, falls back to a per-row Find for legacy rows // that don't have assigned_user_id set. $assignee = null; $assignedId = $d->assigned_user_id ?? ($d->user_id ?? null); if ($assignedId) { $assignee = $d->relationLoaded('assignedUser') ? $d->assignedUser : \App\Models\User::find($assignedId); } $assigneeName = $assignee?->name ?: 'Unassigned'; $assigneeInitials = mb_strtoupper( mb_substr( collect(preg_split('/\s+/', $assigneeName)) ->map(fn($p) => mb_substr($p, 0, 1)) ->take(2) ->implode(''), 0, 2, ), ) ?: '?'; // Last-active label — relative ("just now" / "2 min ago") and // an absolute clock time underneath ("14:42 IST"). Falls back // to "—" when the device has never been seen. $lastSeen = $d->last_seen_at; $lastRelative = $lastSeen ? $lastSeen->diffForHumans(short: true) : '—'; $lastAbsolute = $lastSeen ? $lastSeen->copy()->setTimezone(config('app.timezone'))->format('H:i') . ' ' . now()->format('T') : ($active ? 'live' : 'disconnected'); // Device meta line (under the name) — Region · model / "Test number"-style // hint. We don't have a model field yet, so just show region + a // role hint based on active state. $metaLine = trim(($d->region ?: '') . ($active ? ' · active' : ''), ' ·') ?: 'Spare line'; @endphp
{{-- ☑️ row checkbox (for the future bulk-action bar) --}}
{{-- Device: coloured icon avatar + name + meta line --}}
{{ $d->device_name }}
{{ $metaLine }}
{{-- Mobile number --}}
{{ $d->display_phone }}
{{-- User (avatar + name) --}}
{{ $assigneeName }}
{{-- Last active — relative on top, absolute clock under --}}
{{ $lastRelative }}
{{ $lastAbsolute }}
{{-- Sent (24h) --}}
{{ $d->sent_24h > 0 ? number_format($d->sent_24h) : '—' }}
{{-- Status pill --}}
{{ $pill['label'] }}
{{-- Actions: Analytics · QR · Edit · Refresh · (Connect / Disconnect) · Delete --}}
@if ($active) {{-- Connected: refresh QR / edit / disconnect / delete --}} @else {{-- Disconnected: QR connect / edit / delete --}} @endif
@empty @include('user.partials.empty-state', [ 'class' => 'm-4', 'message' => 'No devices match the current filters. Try clearing filters or pair a new device.', 'resetHref' => url('/devices'), 'actionButtonAttrs' => 'onclick="document.getElementById(\'devices-add-btn\')?.click()"', 'actionLabel' => 'Add device', ]) @endforelse