{{-- /devices when active engine = waba. Renders a card grid of WaProviderConfig rows (one card per WABA phone number) instead of the Baileys device table. Vars expected (passed from DevicesController): $wabaAccounts — Collection of WaProviderConfig rows $embeddedSignupReady — bool, opens FB SDK iframe modal when true $embeddedSignupConfigId — string $wabaAppId — string --}}
@php // Workspace AI agents for the per-number "auto-reply agent" picker. $__aiAgents = \App\Models\AiAgent::where('workspace_id', auth()->user()?->current_workspace_id) ->orderBy('name')->get(['id', 'name']); @endphp {{-- ── BSP billing choice — shown once a WABA number is connected. The client picks who bills them: Meta directly (normal plan system) or through us (prepaid wallet, we bill per message, Meta invoices us). --}} @if ($wabaAccounts->isNotEmpty()) @php $bspWs = auth()->user()?->currentWorkspace; $bspReseller = (bool) ($bspWs?->billsToPlatform()); $bspAvailable = class_exists(\App\Bsp\Services\CreditAllocationService::class) && app(\App\Bsp\Services\CreditAllocationService::class)->source()->isConfigured(); @endphp
{{ __('billing for this number') }}

{{ __('How do you want to be billed for messages?') }}

{{-- Card A — Meta bills directly (normal system) --}}
@csrf
{{-- Card B — Bill through us (BSP wallet) --}}
@csrf
@endif {{-- Empty state --}} @if ($wabaAccounts->isEmpty()) @if (!empty($multiEngine)) {{-- Multi-engine: NO big connect card on the page. Connect happens via "Add device" → Meta (WABA) modal. Just a slim "not connected" line. --}}
{{ __('No WhatsApp Business numbers connected yet. Click "Add device" above, then choose Meta (WABA).') }}
@else
{{ __('Connect your first WABA number') }}

{{ __('Each merchant connects their own WhatsApp Business Account from Meta Business Suite. You can add multiple numbers per workspace.') }}

@if ($embeddedSignupReady)
@endif
@endif @else {{-- Filter + add bar --}}
{{ __('Workspace · WABA accounts') }} {{ $wabaAccounts->count() }} {{ __('connected') }}
{{-- Card grid (one per row) --}}
@foreach ($wabaAccounts as $waba) @php $meta = is_array($waba->meta_json) ? $waba->meta_json : []; $wabaId = (string) ($meta['waba_id'] ?? ''); $pnid = (string) ($meta['phone_number_id'] ?? ''); $bizId = (string) ($meta['business_id'] ?? ''); $verified = (string) ($meta['verified_name'] ?? ($waba->display_label ?: ($waba->phone_number ?: 'Unnamed WABA'))); $quality = strtoupper((string) ($meta['quality_rating'] ?? '')); $tier = (string) ($meta['messaging_limit_tier'] ?? ''); // Coexistence: the number is still live on the WhatsApp // Business app (onboarded in coexistence mode, /register // skipped). Badge it so operators can tell at a glance. $isCoexistence = (bool) ($meta['coexistence'] ?? false); $isConnected = $waba->isConnected(); $qualityColor = match ($quality) { 'GREEN' => 'bg-wa-mint text-wa-deep border-wa-green/40', 'YELLOW' => 'bg-accent-amber/10 text-accent-amber border-accent-amber/40', 'RED' => 'bg-accent-coral/10 text-accent-coral border-accent-coral/40', default => 'bg-paper-100 text-ink-700 border-paper-200', }; @endphp
@if ($waba->is_primary) Primary @endif
{{ $verified }}
{{ $waba->phone_number ?: '+— unknown' }}
@if ($isCoexistence) {{ __('Coexistence') }} @endif
{{ __('WABA ID') }}
{{ $wabaId ?: '—' }}
{{ __('Phone ID') }}
{{ $pnid ?: '—' }}
{{ __('Quality') }}
{{ $quality ?: 'Unrated' }}
{{ __('Tier') }}
{{ $tier ? str_replace('TIER_', '', $tier) . ' / day' : '—' }}
{{ $isConnected ? 'Connected' : 'Disconnected' }} @if ($waba->connected_at) · {{ $waba->connected_at->diffForHumans() }} @endif @if ($isConnected) @include('user.devices._inbound_badge', ['wired' => (is_array($waba->meta_json ?? null) ? ($waba->meta_json['inbound_wired'] ?? null) : null)]) @endif
@if (!$waba->is_primary && $isConnected)
@csrf
@endif {{ __('Health') }} @if ($isConnected) {{-- Re-point this number's Meta webhook (override_callback_uri) at our current inbound URL, reusing the stored token. One-click fix for inbound going dead after a domain change. --}}
@csrf
@endif {{-- Register on WhatsApp Cloud API — completes registration so Meta stops rejecting sends with (#133010) "Account not registered". Shown regardless of CONNECT state (a PENDING pure Cloud-API number needs exactly this), but ONLY for non-coexistence numbers: Meta rejects /register for SMB / coexistence numbers with "(#100) Register endpoint is not available for SMB businesses", so the button would only ever fail there (they don't use Cloud-API registration anyway). --}} @unless ($isCoexistence)
@csrf
@endunless @if ($wabaId) Meta @endif @if ($isConnected)
@csrf @method('DELETE')
@endif {{-- Remove = permanently delete the number from this workspace's device list (wabaRemove deletes the wa_provider_configs row). --}}
@csrf @method('DELETE')
{{-- Per-number automation: default AI agent + business/segment tag. The agent auto-replies to every new chat on this number; the business tag is applied to each inbound chat AND its contact so contacts are grouped by which number/business they belong to. --}}
@csrf @if ($__aiAgents->isNotEmpty()) @endif {{ __('Auto-assigns the agent and tags every new chat + contact on this number.') }}
@endforeach
{{ $wabaAccounts->count() }} WABA {{ \Illuminate\Support\Str::plural('account', $wabaAccounts->count()) }} {{ __('connected') }}
{{ __('Primary number is used as the default sender') }}
@endif {{-- Connect modals (hidden until [data-waba-connect="..."] click) --}} @include('user.devices._waba_modals', [ 'embeddedSignupReady' => $embeddedSignupReady ?? false, 'embeddedSignupConfigId' => $embeddedSignupConfigId ?? '', 'embeddedSignupVersion' => $embeddedSignupVersion ?? 'v2', 'embeddedSignupCoexConfigId' => $embeddedSignupCoexConfigId ?? '', 'wabaAppId' => $wabaAppId ?? '', ])