<?php

declare(strict_types=1);

use App\Support\Workspaces\WorkspaceContext;

it('shows Provider Connections under the Settings → Integrations navigation section for entitled users', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    $this->actingAs($user)
        ->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
        ->get(route('admin.operations.index', ['workspace' => (int) $tenant->workspace_id]))
        ->assertOk();

    $groups = app(\Filament\Navigation\NavigationManager::class)->get();

    $settingsGroup = collect($groups)
        ->first(static fn (\Filament\Navigation\NavigationGroup $group): bool => $group->getLabel() === 'Settings');

    expect($settingsGroup)->not->toBeNull();

    $items = collect($settingsGroup->getItems());

    $integrationsItem = $items
        ->first(static fn (\Filament\Navigation\NavigationItem $item): bool => $item->getLabel() === 'Integrations');

    expect($integrationsItem)->not->toBeNull();

    $childLabels = collect($integrationsItem->getChildItems())
        ->map(static fn (\Filament\Navigation\NavigationItem $item): string => $item->getLabel())
        ->values()
        ->all();

    expect($childLabels)->toContain('Provider Connections');
});
