@php use App\Filament\Pages\ChooseTenant; use App\Filament\Pages\ChooseWorkspace; use App\Models\Tenant; use App\Models\User; use App\Support\OperateHub\OperateHubShell; use App\Support\Workspaces\WorkspaceContext; use Filament\Facades\Filament; /** @var WorkspaceContext $workspaceContext */ $workspaceContext = app(WorkspaceContext::class); $resolvedContext = app(OperateHubShell::class)->resolvedContext(request()); $workspace = $resolvedContext->workspace; $user = auth()->user(); $tenants = collect(); if ($user instanceof User && $workspace) { $tenants = collect($user->getTenants(Filament::getCurrentOrDefaultPanel())) ->filter(fn ($tenant): bool => $tenant instanceof Tenant && (int) $tenant->workspace_id === (int) $workspace->getKey()) ->values(); } $currentTenant = $resolvedContext->tenant; $currentTenantId = $currentTenant instanceof Tenant ? (int) $currentTenant->getKey() : null; $currentTenantName = $currentTenant instanceof Tenant ? $currentTenant->getFilamentName() : null; $lastTenantId = $workspaceContext->lastTenantId(request()); $canClearTenantContext = $currentTenant instanceof Tenant || $lastTenantId !== null; @endphp @php $tenantLabel = $currentTenantName ?? __('localization.shell.no_tenant_selected'); $workspaceLabel = $workspace?->name ?? __('localization.shell.choose_workspace'); $hasActiveTenant = $currentTenantName !== null; $managedTenantsUrl = $workspace ? route('admin.workspace.managed-tenants.index', ['workspace' => $workspace]) : route('admin.onboarding'); $workspaceUrl = $workspace ? route('admin.home') : ChooseWorkspace::getUrl(panel: 'admin'); $tenantTriggerLabel = $workspace ? $tenantLabel : __('localization.shell.choose_workspace'); $localePlane = Filament::getCurrentPanel()?->getId() === 'tenant' ? 'tenant' : 'admin'; @endphp
{{-- Workspace label: standalone link --}} {{ $workspaceLabel }} @if ($workspace) @endif {{-- Dropdown trigger: tenant label + chevron --}}
@if ($resolvedContext->showsRecoveryNotice())
{{ __('localization.shell.context_unavailable') }}
@if ($workspace)
{{ __('localization.shell.context_unavailable_workspace') }}
@else
{{ __('localization.shell.context_unavailable_no_workspace') }}
@endif
@endif {{-- Workspace section --}} @if ($workspace)
{{-- Tenant section --}}
{{ __('localization.shell.selected_tenant') }}
@if ($resolvedContext->pageCategory->requiresExplicitTenant() && $hasActiveTenant)
@if ($canClearTenantContext)
@csrf
@endif
@else @if ($tenants->isEmpty())
{{ __('localization.shell.no_active_tenants') }}
{{ __('localization.shell.view_managed_tenants') }}
@else @if (! $hasActiveTenant)
{{ __('localization.shell.workspace_wide_available') }}
@endif
@foreach ($tenants as $tenant) @php $isActive = $currentTenantId !== null && (int) $tenant->getKey() === $currentTenantId; @endphp
@csrf
@endforeach
@if ($canClearTenantContext)
@csrf
@endif @endif @endif
@else
{{ __('localization.shell.choose_workspace_first') }}
@endif
@include('filament.partials.locale-switcher', ['plane' => $localePlane, 'showPreference' => true, 'embedded' => true])