@php $tabs = [ 'overview' => ['Overview', 'M2 11l3-5 3 3 3-6 3 4', null], 'orders' => [ 'Orders', 'M2 4h2l1.5 8h7l1-5H6 M6 13a1 1 0 1 0 0-2 1 1 0 0 0 0 2z M11 13a1 1 0 1 0 0-2 1 1 0 0 0 0 2z', \App\Models\WaOrder::forWorkspace(auth()->user()->current_workspace_id ?? 0)->count(), ], 'products' => [ 'Products', 'M2 5l6-3 6 3v6l-6 3-6-3z M2 5l6 3 6-3 M8 8v6', \App\Models\WaProduct::forWorkspace(auth()->user()->current_workspace_id ?? 0)->count(), ], 'storefront' => ['Storefront', 'M2 5h12v8H2z M2 8h12 M5 5v3', null], 'coupons' => [ 'Coupons', 'M2 6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2 1.5 1.5 0 0 0 0 4 2 2 0 0 1-2 2H4a2 2 0 0 1-2-2 1.5 1.5 0 0 0 0-4z M9 5l-2 6', \App\Models\WaCoupon::where('workspace_id', auth()->user()->current_workspace_id ?? 0)->count(), ], 'reviews' => [ 'Reviews', 'M8 2l1.8 3.6L14 6.2l-3 2.9.7 4.1L8 11.3 4.3 13.2 5 9.1 2 6.2l4.2-.6z', \App\Models\WaProductReview::where('workspace_id', auth()->user()->current_workspace_id ?? 0) ->where('status', 'pending') ->count(), ], ]; $current = $current ?? request()->segment(2) ?: 'overview'; $publicUrl = isset($sf) && $sf ? $sf->public_url : null; // "Live" / "Setup" should reflect ANY route to WhatsApp: // • workspace-level provider config (WABA/Twilio/etc) connected, OR // • storefront has a bound device that's still 'connected', OR // • current user owns any connected device row. $cfgConnected = isset($cfg) && $cfg && $cfg->isConnected(); $sfDevice = isset($sf) && $sf && $sf->device_id ? \App\Models\Device::find($sf->device_id) : null; $sfDeviceLive = $sfDevice && $sfDevice->status === 'connected'; $anyDeviceLive = \App\Models\Device::query()->forCurrentWorkspace()->where('status', 'connected')->exists(); $waLive = $cfgConnected || $sfDeviceLive || $anyDeviceLive; if ($cfgConnected) { $cfgLabel = \App\Enums\WaProvider::tryFrom($cfg->provider)?->label() ?? strtoupper($cfg->provider); } elseif ($sfDeviceLive) { $cfgLabel = 'Unofficial API · ' . trim(($sfDevice->country_code ?? '') . ' ' . ($sfDevice->phone_number ?? '')); } elseif ($anyDeviceLive) { $cfgLabel = 'Device connected · /devices'; } else { $cfgLabel = 'Not connected'; } @endphp