<?php

declare(strict_types=1);

use App\Models\Tenant;
use App\Support\Workspaces\WorkspaceOverviewBuilder;

it('keeps switch workspace visible while hiding manage workspaces and unauthorized tenant counts for readonly members', function (): void {
    $tenantA = Tenant::factory()->create(['status' => 'active']);
    [$user, $tenantA] = createUserWithTenant($tenantA, role: 'owner', workspaceRole: 'readonly');

    Tenant::factory()->create([
        'status' => 'active',
        'workspace_id' => (int) $tenantA->workspace_id,
        'name' => 'Inaccessible Tenant',
    ]);

    $workspace = $tenantA->workspace()->firstOrFail();

    $overview = app(WorkspaceOverviewBuilder::class)->build($workspace, $user);
    $quickActionKeys = collect($overview['quick_actions'])->pluck('key')->all();

    expect($overview['accessible_tenant_count'])->toBe(1)
        ->and($quickActionKeys)->toContain('switch_workspace')
        ->and($quickActionKeys)->not->toContain('manage_workspaces');
});
