@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(), ], 'groups' => [ 'Groups', 'M5 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4z M11 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4z M1.5 13c0-2 1.3-3 3.5-3s3.5 1 3.5 3 M7.5 13c0-2 1.3-3 3.5-3s3.5 1 3.5 3', \App\Models\WaGroup::where('workspace_id', 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(), ], 'payments' => [ 'Payments', 'M1.5 4.5h13v7h-13z M1.5 7h13 M4 9.5h3', \App\Models\WorkspacePaymentConfig::where('workspace_id', auth()->user()->current_workspace_id ?? 0)->count(), ], // Checkout gateways moved to Settings → Payment gateways (one home for the // merchant's own keys, shared by store checkout + appointment booking). 'customers' => [ 'Customers', 'M8 8a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z M2.5 14c0-2.5 2.2-4 5.5-4s5.5 1.5 5.5 4', \App\Models\WaCustomerProfile::where('workspace_id', auth()->user()->current_workspace_id ?? 0)->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