@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. // Multi-engine: render a section per ENABLED engine (not just the default). // $activeEngine stays the "default" engine (shown with a badge). The Baileys // filter rail / help cards / pair modal stay gated on whether Baileys is on. $enabledEngines = $enabledEngines ?? [$activeEngine ?? 'baileys']; $hasBaileys = in_array('baileys', $enabledEngines, true); $hasWaba = in_array('waba', $enabledEngines, true); $hasTwilio = in_array('twilio', $enabledEngines, true); // Show the WABA section whenever the workspace HAS WABA accounts — even if // WABA isn't a currently-"connected" engine. Disconnecting a number keeps // its row as status=disconnected; gating the whole section on $hasWaba made // that number's card vanish entirely (looked auto-removed). $showWaba = $hasWaba || (isset($wabaAccounts) && $wabaAccounts->count() > 0); $multiEngine = count($enabledEngines) > 1; $engine = $activeEngine ?? 'baileys'; $isBaileysView = $hasBaileys; $channelStatus = $channelStatus ?? []; // Instagram (via the linked Instaflow install). A separate channel type — NOT // a WhatsApp send engine — so it lives outside $enabledEngines. $hasInstagram // gates the "Add Instagram account" affordances; $instagramAccounts are this // workspace's linked mirror rows. When either the workspace runs 2+ WA engines // OR Instagram is available, the header "Add device" button opens the channel // chooser (so IG has somewhere to be added even on a single-engine workspace). $hasInstagram = $hasInstagram ?? false; $instagramAccounts = $instagramAccounts ?? collect(); $instaflowUrl = $instaflowUrl ?? ''; $hasInstagramRows = $hasInstagram && count($instagramAccounts) > 0; // Connect mode: ON = clients use their OWN Meta app (paste a token); OFF = // connect via this platform app ("Continue with Facebook"). Admin-controlled. $metaOwnApp = (bool) \App\Models\SystemSetting::get('meta_allow_manual_app', false); // Workspace has its OWN Instagram-Login app → Instagram connects via the // Instagram-Login OAuth ("Connect account"), which delivers DMs. Takes // precedence over the manual-token modal for Instagram. $igLoginOwnApp = (bool) (auth()->user()?->currentWorkspace?->ownIgLoginApp()); // Facebook Pages channel (core). Availability is admin-enabled; the connect // flow + connected Pages are read here directly (no controller change). Like // Instagram, it's a bolt-on channel — not a WhatsApp send engine. $hasFacebook = (bool) \App\Models\SystemSetting::get('facebook_enabled', false); $__fbWsId = (int) (auth()->user()?->current_workspace_id ?? 0); if ($hasFacebook) { // Inline, cache-gated hourly token health check (no-cron policy). try { \App\Services\Facebook\FacebookTokenRefreshSweeper::run($__fbWsId); } catch (\Throwable $e) {} } $facebookPages = $hasFacebook ? \App\Models\FacebookPage::forWorkspace($__fbWsId)->orderBy('name')->get() : collect(); $fbPageCount = $facebookPages->count(); // Facebook mirror rows are appended into the "Connected channels" table // (same as Instagram) — this gates rendering that table when Facebook is // the only live channel, and folds Facebook into the footer counts. $hasFacebookRows = $hasFacebook && $fbPageCount > 0; // TikTok channel (core) — same inline treatment as Facebook. $hasTiktok = (bool) \App\Models\SystemSetting::get('tiktok_enabled', false); if ($hasTiktok) { try { \App\Services\Tiktok\TiktokTokenRefreshSweeper::run($__fbWsId); } catch (\Throwable $e) {} } $tiktokAccounts = $hasTiktok ? \App\Models\TiktokAccount::forWorkspace($__fbWsId)->orderBy('display_name')->get() : collect(); $hasTiktokRows = $hasTiktok && $tiktokAccounts->count() > 0; // Telegram channel (core) — Bot API bots + optional MTProto account, both // connected on /telegram. Same inline treatment as TikTok. $hasTelegram = (bool) \App\Models\SystemSetting::get('telegram_enabled', false); $telegramBots = ($hasTelegram && class_exists(\App\Models\TelegramBot::class)) ? \App\Models\TelegramBot::allForWorkspace($__fbWsId) : collect(); $telegramAccounts = ($hasTelegram && class_exists(\App\Models\TelegramAccount::class)) ? \App\Models\TelegramAccount::allForWorkspace($__fbWsId) : collect(); $hasTelegramRows = $hasTelegram && ($telegramBots->count() > 0 || $telegramAccounts->count() > 0); // SMS channel (core) — Twilio / MSG91. Connected on /sms (reuses the Twilio // keys). Gated on the admin sms_enabled toggle, like telegram/tiktok. $hasSms = (bool) \App\Models\SystemSetting::get('sms_enabled', false); // LINE channel (core) — LINE Official Account (Messaging API). Connected on // /line by pasting a channel access token + secret. Gated on line_enabled. $hasLine = (bool) \App\Models\SystemSetting::get('line_enabled', false); // WeChat channel (core) — WeChat Official Account. Connected on /wechat by // pasting AppID + AppSecret + Token. Gated on wechat_enabled. $hasWeChat = (bool) \App\Models\SystemSetting::get('wechat_enabled', false); // Viber channel (core) — Viber Public Account. Connected on /viber by pasting // the bot auth token. Gated on viber_enabled. $hasViber = (bool) \App\Models\SystemSetting::get('viber_enabled', false); // Email channel (via the linked MailTrixy install). Mailboxes connect once // on MailTrixy; the card here links one into this workspace (mirror rows, // like Instagram). Gated on email_enabled + a configured bridge. // Resolved by DevicesController and passed in — the 15s background refresh // re-renders _channel_rows from the controller payload alone, so computing // these only here made the mailbox rows vanish moments after page load. // Fall back to a local resolve so a direct render of this view still works. $hasEmail = $hasEmail ?? ((bool) \App\Models\SystemSetting::get('email_enabled', false) && \App\Services\Mailtrixy\MailtrixyClient::fromSettings()->isConfigured()); $emailAccounts = $emailAccounts ?? ($hasEmail ? \App\Models\WorkspaceEmailAccount::forWorkspace($__fbWsId)->orderBy('email')->get() : collect()); // NATIVE email (own IMAP/SMTP, no MailTrixy) — available whenever the // platform toggle is on and the plan carries access_email. Independent of // $hasEmail (which also requires a configured MailTrixy bridge), so native // connect works with the bridge absent. Drives the Email chooser card + the // native connect modal below. $hasEmailNative = $hasEmailNative ?? ((bool) \App\Models\SystemSetting::get('email_enabled', false) && \App\Services\PlanLimitGuard::hasFeature(\App\Models\Workspace::find($__fbWsId), 'access_email')); // Threads (Meta) — publishing channel; connects on /threads (OAuth). Connected // accounts are woven into the Connected channels table as rows, like TikTok. // Prefer the controller-passed collection (the 15s AJAX refresh re-renders // _channel_rows from the controller payload, so a view-only resolve would // make connected Threads rows vanish moments after load); fall back to a // local resolve so a direct render of this view still works. $hasThreads = (bool) \App\Models\SystemSetting::get('threads_enabled', false); $threadsAccounts = $threadsAccounts ?? (($hasThreads && class_exists(\App\Models\ThreadsAccount::class)) ? \App\Models\ThreadsAccount::forWorkspace($__fbWsId)->orderBy('username')->get() : collect()); $hasThreadsRows = $hasThreads && $threadsAccounts->count() > 0; // LinkedIn + X (core publishing channels) — same controller-payload-first // resolution as Threads so the 15s background refresh keeps the rows. $hasLinkedin = (bool) \App\Models\SystemSetting::get('linkedin_enabled', false); $linkedinAccounts = $linkedinAccounts ?? (($hasLinkedin && class_exists(\App\Models\LinkedInAccount::class)) ? \App\Models\LinkedInAccount::forWorkspace($__fbWsId)->orderByDesc('id')->get() : collect()); $hasLinkedinRows = $hasLinkedin && $linkedinAccounts->count() > 0; $hasX = (bool) \App\Models\SystemSetting::get('x_enabled', false); $xAccounts = $xAccounts ?? (($hasX && class_exists(\App\Models\XAccount::class)) ? \App\Models\XAccount::forWorkspace($__fbWsId)->orderByDesc('id')->get() : collect()); $hasXRows = $hasX && $xAccounts->count() > 0; $showChooser = $multiEngine || $hasInstagram || $hasFacebook || $hasTiktok || $hasTelegram || $hasSms || $hasLine || $hasWeChat || $hasViber || $hasEmail || $hasEmailNative || $hasThreads || $hasLinkedin || $hasX; // Embed mode (?embed=1): this page is iframed inside the GLOBAL "Connect // device" popover (x-user.connect-device-sheet). Force the channel chooser // to render; the embed CSS below hides the app chrome so only the chooser + // connect flow show, and the JS posts a message to the parent on success. $embed = request()->boolean('embed'); // NOTE: $showChooser is computed ABOVE, so forcing $multiEngine alone does // nothing — the chooser (and its cards) would never render and the popover // iframe shows blank. Force $showChooser too so the channel chooser always // renders inside the Connect-device popover, even on a single-engine workspace. if ($embed) { $multiEngine = true; $showChooser = true; } @endphp @if ($embed) {{-- Embedded inside the global Connect-device popover: strip the app chrome so only the channel chooser + connect flow show, auto-open the chooser, and tell the parent window when a device connects. --}} @endif @if (session('status')) {{-- A connect just succeeded server-side. If this page is shown inside the global Connect-device popover (iframe) — e.g. Twilio / WABA redirect here after a native POST — tell the parent to close + refresh the picker. No-op on the real /devices page (not iframed). --}} @endif
@if (session('status'))
{{ session('status') }}
@endif {{-- WABA connect (Embedded Signup / manual) errors. Without this, a failed save — e.g. Meta returned no phone number, token exchange failed, or the Meta app lacks whatsapp_business_management — was SILENTLY swallowed: the FB popup "connected" but no device + no reason shown. Surface every validation error so the merchant can act on it. --}} @if ($errors->any())
{{ __('WhatsApp connection could not be completed') }}
    @foreach ($errors->all() as $err)
  • {{ $err }}
  • @endforeach
{{ __('Tip: if Meta did not return a phone number, finish your WABA setup in Meta Business Suite (add a payment method + select a verified number), or use "Add WABA account → paste credentials manually".') }}
@endif
{{-- Channels redesign: full-width, no left filter rail. The Unofficial-API status filters live as tabs inside the device table below. --}} @if (false) @endif
@php // Each engine renders its own section now — independent, not // mutually exclusive. (Kept as locals for the header + buttons.) $isWaba = $hasWaba; $isTwilio = $hasTwilio; @endphp
{{ __('Workspace') }} · {{ auth()->user()?->currentWorkspace?->name ?: brand_name() }}

{{ __('Omni') }} {{ __('channels') }}

{{ __('Connect WhatsApp, Instagram, Telegram and more — every conversation routes into one inbox and runs through the same flows, campaigns and automations.') }}

{{ $totals['connected'] }} {{ __('live') }} @if (($totals['failed_24h'] ?? 0) > 0) {{ $totals['failed_24h'] }} {{ __('attention') }} @endif {{-- Multi-engine OR Instagram available: one "Add device" button opens the channel chooser MODAL (cards → each opens that channel's connect flow). Single-engine with no extra channel: the original per-engine buttons. --}} @if ($showChooser) @else @if ($hasWaba) @endif @if ($hasBaileys) @endif @endif
@php // Real channel/account tallies from the connected engines. $igCount = ($hasInstagram && isset($instagramAccounts)) ? count($instagramAccounts) : 0; // Facebook Pages count as connected accounts too (mirrors Instagram). // totals() already folds connected Pages into the KPI numbers, so // this local is only for the "+N FB" Accounts sub-label + $liveTypes. $fbCount = ($hasFacebook && isset($facebookPages)) ? count($facebookPages) : 0; $acctConnected = (int) ($totals['connected'] ?? 0) + $igCount; $acctTotal = (int) ($totals['total'] ?? 0) + $igCount; $liveTypes = 0; if ($hasBaileys || $devices->count()) { $liveTypes++; } if ($hasWaba || (isset($wabaAccounts) && $wabaAccounts->count())) { $liveTypes++; } if ($hasTwilio || ! empty($twilioAccount)) { $liveTypes++; } if ($hasInstagram) { $liveTypes++; } if ($hasFacebookRows) { $liveTypes++; } // The remaining core channels are listed as rows too, so a // connected one is a live channel type and must be counted — // TikTok was visible but uncounted, and Threads was missing // from this tally entirely. if (! empty($hasTiktokRows)) { $liveTypes++; } if (! empty($hasThreadsRows)) { $liveTypes++; } if (! empty($hasLinkedinRows)) { $liveTypes++; } if (! empty($hasXRows)) { $liveTypes++; } if (! empty($hasTelegramRows)) { $liveTypes++; } if (isset($emailAccounts) && $emailAccounts->count()) { $liveTypes++; } $healthPct = $acctTotal > 0 ? round(($acctConnected / max($acctTotal, 1)) * 100) : 100; @endphp
{{ __('Channels live') }}
{{ $liveTypes }}{{ $totals['connected'] }} {{ __('accounts live') }}
{{ __('Accounts') }}
{{ $totals['total'] }}{{ __('numbers') }}{{ $igCount ? ' · +' . $igCount . ' IG' : '' }}{{ $fbCount ? ' · +' . $fbCount . ' FB' : '' }}
{{ __('Routed · 24h') }}
{{ number_format($totals['sent_24h']) }}{{ __('messages') }}
{{ __('Health') }}{{ $healthPct }}%
{{ $healthPct >= 90 ? __('healthy') : __('attention') }}
{{-- Connected Facebook Pages are woven into the "Connected channels" table below as ROWS (see _channel_rows) — exactly like Instagram — rather than a separate card here. --}} {{-- Detailed management surface (existing, fully-wired). --}}
{{ __('Manage & details') }}
@php // Per-section label (engine NAME only — no "default" badge, // which confused operators). Shown above each panel when the // workspace runs more than one engine. $engLabel = function ($eng, $name) use ($multiEngine) { if (!$multiEngine) return ''; return '
' . e($name) . '
'; }; @endphp @unless ($multiEngine) @if ($showWaba) {{-- Meta (WABA) — one card per WABA number (incl. disconnected). --}} {!! $engLabel('waba', __('Meta (WABA)')) !!} @include('user.devices._waba_section') @endif @if ($hasTwilio) {{-- Twilio — account card once connected. The connect form lives in a modal opened from "Add device" → Twilio (see below). --}} {!! $engLabel('twilio', __('Twilio')) !!} @include('user.devices._twilio_section') @endif @endunless @if ($hasBaileys || $multiEngine || $hasInstagramRows || $hasFacebookRows || ($hasTiktokRows ?? false)) {{-- The device table is the ONE table. In multi-engine it doubles as the "Connected channels" table: Baileys devices render via _table, and the connected WABA + Twilio accounts are appended as rows below (same columns). Renders in multi-engine even WITHOUT Baileys — otherwise a WABA+Twilio-only workspace loses the whole table and its connected channels never show. --}} @if ($multiEngine)
{{ __('Connected channels') }}
@else {!! $engLabel('baileys', __('Unofficial API')) !!} @endif
{{-- 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
{{-- Chunked "Check status" — verifies every device's real Baileys state a small batch at a time so a 300-number workspace can't crash the request. Updates the table when done. --}} {{-- Bulk check (GET endpoint, CSRF-exempt) — reliable at 300 devices. --}}
{{-- Column header strip — matches the row grid template below --}}
{{-- Render the Baileys device rows (with their empty-state) only when there are Baileys devices, OR in single-engine mode where the "No devices" empty-state is the right prompt. In multi-engine with 0 Baileys devices, the connected WABA/Twilio rows below carry the table — so we skip the empty Baileys "No data found". --}} @if ($hasBaileys && ($devices->count() > 0 || !$multiEngine)) @include('user.devices._table', ['devices' => $devices, 'channelTag' => $multiEngine, 'hideEmpty' => $multiEngine || $hasInstagramRows || $hasFacebookRows || $hasTiktokRows]) @endif @include('user.devices._channel_rows') {{-- Closes #devices-list. It used to close ABOVE the WABA/Twilio loop, which left those rows as SIBLINGS of the grid source rather than children — and list-grid-toggle.js reads only source.children. So card view cloned the Baileys rows alone ("1 of 1") while list view still showed all three, since the rows render identically either way. --}}
{{-- Footer: counts + plan limit (matches mockup) --}}
@php // In multi-engine the table also appends the connected WABA/Twilio // rows (not paginated), so "Showing X of Y" must count them too — // else a WABA-only workspace reads "Showing 0 of 0" under 1 visible row. $extraChannels = ($multiEngine && isset($connectedChannels)) ? $connectedChannels->where('engine', '!=', 'baileys')->count() : 0; // Instagram mirror rows are appended below too (independent of engine). $extraChannels += count($instagramAccounts ?? []); // Facebook Page rows are appended below too (mirrors Instagram). $extraChannels += count($facebookPages ?? []); $shownCount = $devices->count() + $extraChannels; $totalCount = (method_exists($devices, 'total') ? $devices->total() : ($counts['all'] ?? 0)) + $extraChannels; @endphp
{{ __('Showing') }} {{ $shownCount }} of {{ number_format($totalCount) }}
{{ __('Plan limit:') }} {{ $totals['total'] ?? 0 }} / {{ (isset($deviceLimit) && (int) $deviceLimit > 0) ? (int) $deviceLimit : '∞' }} {{ __('numbers') }}
@include('user.partials.pagination', [ 'paginator' => $devices, 'dataAttr' => 'data-devices-page', 'label' => 'devices', ])
@endif {{-- /hasBaileys — Baileys device-table 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 chooser modal (multi-engine, or when Instagram is available). The header "Add device" button opens this; each card then opens that channel's own connect modal. --}} @if ($showChooser) @endif {{-- Native email connect modal — opened from the Email chooser card (data-email-connect-open) or the sidebar Email link (#connect-email). --}} @if (! empty($hasEmailNative)) @include('user.email._connect_modal') @endif {{-- Instagram connect modal — "link an account already on Instaflow" (the primary path) plus "connect a new account" (popup OAuth). Opened from the chooser card or a channel row's Manage button (both data-instagram-connect). --}} @if ($hasInstagram) @endif {{-- Email connect modal — links a mailbox already connected on the linked MailTrixy install into this workspace (mirror row, like Instagram). Shows this workspace's linked mailboxes (refresh/unlink) plus the ones still available to link (loaded on open). Opened from the chooser card (data-email-connect). --}} @if ($hasEmail) @endif {{-- Twilio connect modal (multi-engine only). Opened from the chooser card or the Twilio section's "Connect Twilio" button (both data-twilio-connect). --}} @if ($hasTwilio && $multiEngine) @endif {{-- WABA connect modals for multi-engine (single-engine gets them via _waba_section, which isn't rendered in the unified-table view). --}} @if ($hasWaba && $multiEngine) @include('user.devices._waba_modals', [ 'embeddedSignupReady' => $embeddedSignupReady ?? false, 'embeddedSignupConfigId' => $embeddedSignupConfigId ?? '', 'embeddedSignupVersion' => $embeddedSignupVersion ?? 'v2', 'embeddedSignupCoexConfigId' => $embeddedSignupCoexConfigId ?? '', 'wabaAppId' => $wabaAppId ?? '', ]) @endif {{-- 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 --}} {{-- Facebook connect modal — "Continue with Facebook" (account login → all Pages) OR paste a Page access token manually. Opened from the chooser card ([data-facebook-connect]). --}} @if ($hasFacebook)
has('facebook') || $errors->has('page_access_token')) data-fb-open-on-load="1" @endif @if (old('page_access_token') || $errors->has('page_access_token')) data-fb-manual-open="1" @endif class="hidden fixed inset-0 z-50 items-center justify-center p-5 bg-[rgba(11,31,28,0.46)]">
{{ __('Facebook') }}

{{ __('Connect your Facebook account') }}

@if ($errors->has('facebook') || $errors->has('page_access_token'))
{{ $errors->first('facebook') ?: $errors->first('page_access_token') }}
@endif @if ($metaOwnApp)

{{ __('Paste a Page access token from your own Meta app to connect this Facebook Page. Messenger DMs and comments then route into your inbox.') }}

{{-- Own-app mode → manual token only (no Facebook Login / embedded signup). --}}
@csrf {{-- In-app step-by-step: where to get the token. --}}
{{ __('Where do I get this token?') }}
  1. {{ __('Go to') }} business.facebook.com → {{ __('Settings → Users → System Users.') }}
  2. {{ __('Create a System User (Admin), then Add Assets → assign your Facebook Page (full control).') }}
  3. {{ __('Click Generate token → pick YOUR app (same App ID as in Settings → Meta app).') }}
  4. {{ __('Tick:') }} pages_show_list, pages_messaging, pages_manage_metadata, pages_read_engagement, pages_manage_posts
  5. {{ __('Copy the token and paste it above. (System-User tokens never expire — best for production.)') }}

{{ __('Quick test: developers.facebook.com → Graph API Explorer → pick your app → Generate token → switch to your Page. (Expires in ~1 hour.)') }}

@else {{-- Platform-app mode → Continue with Facebook (OAuth). --}}

{{ __('Log in with Facebook once — every Page your account manages is added automatically. You can then reply to Messenger and comments from your inbox.') }}

{{ __('Continue with Facebook') }} @endif
{{ __('Routes into your inbox instantly') }} {{ __('encrypted') }}
@endif {{-- Instagram (native add-on) connect modal — MANUAL TOKEN ONLY (no Facebook login / embedded signup). Opened from the Instagram chooser card ([data-instagram-native-connect]). --}} @if ($hasInstagram && $metaOwnApp && (bool) \App\Models\SystemSetting::get('instagram_enabled', false))
has('instagram') || $errors->has('access_token')) data-ig-open-on-load="1" @endif class="hidden fixed inset-0 z-50 items-center justify-center p-5 bg-[rgba(11,31,28,0.46)]">
{{ __('Instagram') }}

{{ __('Connect your Instagram account') }}

@if ($errors->has('instagram') || $errors->has('access_token'))
{{ $errors->first('instagram') ?: $errors->first('access_token') }}
@endif

{{ __('Paste an Instagram access token from your own Meta app to connect. The account must be a Business/Creator account. DMs and comments then route into your inbox.') }}

@csrf {{-- In-app step-by-step: where to get the Instagram token. --}}
{{ __('Where do I get this token?') }}
  1. {{ __('Your Instagram must be a Business/Creator account (linked to a Facebook Page).') }}
  2. {{ __('Go to') }} business.facebook.com → {{ __('Settings → Users → System Users → Generate token (pick YOUR app).') }}
  3. {{ __('Add Assets → assign your Instagram account + its Facebook Page.') }}
  4. {{ __('Tick:') }} instagram_basic, instagram_manage_messages, instagram_manage_comments, pages_show_list, pages_read_engagement
  5. {{ __('Copy the token and paste it above.') }}

{{ __('Quick test: developers.facebook.com → Graph API Explorer → pick your app → Generate token with the scopes above.') }}

{{ __('Routes into your inbox instantly') }} {{ __('encrypted') }}
@endif {{-- The device table's "No data found" empty-state is toggled by the list/grid JS, which counts only WhatsApp device rows — so it kept showing ABOVE a live Instagram/Facebook/TikTok channel row. Hide it (inline style beats the JS class) whenever a channel row is present, and keep it hidden if the JS re-shows it. Blade-only; no bundle build. --}} {{-- "Check status" — walks the WHOLE device list in small chunks (cursor by id) so a 300-number workspace verifies every device without the one all-at-once request that crashed. Each chunk updates rows server-side; the table is refreshed at the end. Inline; no bundle rebuild. --}} {{-- Bulk check — GET endpoint (no CSRF), chunked. Logs on the server for every hit so we can see exactly what Node returns. Inline; no build. --}}