@php $devices = $devices ?? collect(); $counts = $counts ?? ['all' => 0, 'connected' => 0, 'disconnected' => 0, 'needs_pair' => 0, 'failed' => 0]; $regionCounts = $regionCounts ?? []; $totals = $totals ?? ['total' => 0, 'connected' => 0, 'sent_24h' => 0, 'failed_24h' => 0]; $currentStatus = $currentStatus ?? 'all'; $currentRegion = $currentRegion ?? 'all'; $currentSearch = $currentSearch ?? ''; $statusList = [ ['key' => 'all', 'label' => 'All devices', 'dot' => null], ['key' => 'connected', 'label' => 'Connected', 'dot' => 'bg-wa-green'], ['key' => 'disconnected', 'label' => 'Disconnected', 'dot' => 'bg-paper-200'], ['key' => 'needs_pair', 'label' => 'Needs re-pair', 'dot' => 'bg-accent-amber'], ['key' => 'failed', 'label' => 'Failed', 'dot' => 'bg-accent-coral'], ]; // The aside + help cards + add-device modal are Baileys-only UI // (status/region filters, pairing tips, QR pairing flow). When the // workspace engine is WABA or Twilio those sections render their // own connector partial which spans the whole content area, so we // hide the Baileys chrome to avoid mixed metaphors and reclaim the // full page width. $engine = $activeEngine ?? 'baileys'; $isBaileysView = $engine === 'baileys'; @endphp
@if (session('status'))
{{ session('status') }}
@endif
@if ($isBaileysView) {{-- Filter rail floats with the page like the Meta Ads left panel: self-start stops it stretching to row height, sticky keeps it in view while the device list scrolls. --}} @endif
@php $isWaba = ($activeEngine ?? 'baileys') === 'waba'; $isTwilio = ($activeEngine ?? 'baileys') === 'twilio'; @endphp
{{ $isWaba ? 'Workspace · WABA accounts' : ($isTwilio ? 'Workspace · Twilio account' : 'Workspace · Bloomly') }}

@if ($isWaba) My {{ __('WABA accounts') }} @else My {{ __('devices') }} @endif

@if ($isWaba) Connect WhatsApp Business Accounts from Meta Business Suite. Multiple numbers per workspace are supported. @else Pair, monitor, and rotate WhatsApp numbers across regions and agents. @endif

{{ $totals['connected'] }} connected {{-- Top-right "Add" button is engine-aware so we don't pop the Baileys QR modal while the workspace is on WABA. --}} @if ($isWaba) @elseif ($isTwilio) {{-- No top-right "add" button in Twilio mode — credentials are pasted inline in the section's empty-state form. --}} @else @endif
{{ __('Total devices') }}
{{ $totals['total'] }}{{ $totals['connected'] }} active
{{ __('Sent (24h)') }}
{{ number_format($totals['sent_24h']) }}{{ __('across all') }}
{{ __('Failed (24h)') }}
{{ number_format($totals['failed_24h']) }}
{{ __('Health') }}{{ $totals['total'] ? round(($totals['connected'] / max($totals['total'], 1)) * 100) : 0 }}%
{{ $totals['connected'] === $totals['total'] && $totals['total'] > 0 ? 'healthy' : 'attention' }}
@if ($isWaba) {{-- WABA mode — replaces the Baileys device table entirely. --}} @include('user.devices._waba_section') @elseif ($isTwilio) {{-- Twilio mode — operator pastes their own Twilio Account SID + Auth Token + From number. Same UX as WABA: connect form on empty state, account card once connected. The creds drive every send path (broadcasts, campaigns, scheduled, auto-reply, inbox reply) for this workspace. --}} @include('user.devices._twilio_section') @else
{{-- Top bar: quick status tabs on the left, search on the right --}}
@if (($counts['needs_pair'] ?? 0) > 0) @endif @if (($counts['failed'] ?? 0) > 0) @endif
{{-- Column header strip — matches the row grid template below --}}
@include('user.devices._table', ['devices' => $devices])
{{-- Footer: counts + plan limit (matches mockup) --}}
{{ __('Showing') }} {{ $devices->count() }} of {{ method_exists($devices, 'total') ? number_format($devices->total()) : number_format($counts['all'] ?? 0) }}
{{ __('Plan limit:') }} {{ $totals['total'] ?? 0 }} / 8 seats
@include('user.partials.pagination', [ 'paginator' => $devices, 'dataAttr' => 'data-devices-page', 'label' => 'devices', ])
@endif {{-- /isWaba — Baileys-mode block ends here --}} @if ($isBaileysView)
{{ __('Help - 01') }}
{{ __('What is a device?') }}

{{ __('A paired WhatsApp number that sends campaigns, broadcasts, flows, and replies through your workspace.') }}

{{ __('Help - 02') }}
{{ __('How do I keep it online?') }}

{{ __('Keep the phone logged into WhatsApp, avoid battery restrictions, and check status before scheduled sends.') }}

{{ __('Help - 03') }}
{{ __('When should I re-pair?') }}

{{ __('Re-pair when a device is disconnected, failed, or has not synced recently before you start another send.') }}

@endif {{-- Footer "Showing X of Y" is now rendered INSIDE the table card --}}
{{-- Add-device modal — same modal pattern the contacts page uses. --}} {{-- Add-device modal. If admin enabled multiple providers, the modal shows tabs (Baileys / WABA / Twilio) and each tab renders its own setup form. If only one provider is enabled, only that tab's contents render — no tabs visible, just the form. --}} {{-- Add-device modal — matches the legacy 2-column design. Left: device details (name + mobile + assign-to + activate toggle). Right: QR placeholder (real QR appears after Save → row's "Connect" button — admin-set Node URL is used automatically; the user never enters it). --}} @if ($isBaileysView) {{-- Connect-device modal — ports the QR / pairing-code flow from the old project's deviceadd.js without changing the existing add- device modal above. The mode-picker step shows two big tiles (Scan QR / Use pairing code); after the user picks one, the matching panel renders with a polling progress bar that drives itself from /devices/{id}/connection-status. --}} @endif {{-- /isBaileysView — modals are Baileys-only --}}