@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: channel icon avatar + name + meta line. The icon+name live in an INNER flex wrapper so they stay side-by-side in the card/grid view too — the grid builder (list-grid-toggle.js) re-wraps each cell in a plain div and would otherwise drop the flex, stacking the name under the icon. Keeping the flex on an inner node that survives the clone keeps the name beside the icon in both views. --}}
{{ $d->device_name }}
@if (!empty($channelTag)){{ __('Unofficial API') }} · @endif{{ $metaLine }}
{{-- Mobile number (masked — last 4 digits only) --}}
{{ mask_phone($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 {{-- Suppress the "no devices" empty-state when the caller is appending connected WABA/Twilio channel rows after this table (multi-engine) — otherwise the empty-state shows ABOVE the connected channels. --}} @unless (!empty($hideEmpty)) @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', ]) @endunless @endforelse