<?php

declare(strict_types=1);

use App\Filament\Resources\ProviderConnectionResource\Pages\ViewProviderConnection;
use App\Models\ProviderConnection;
use App\Support\Auth\UiTooltips;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Livewire\Livewire;

it('renders disabled manage actions with tooltip for tenant members without capability', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'readonly');

    $connection = ProviderConnection::factory()->create([
        'workspace_id' => (int) $tenant->workspace_id,
        'managed_environment_id' => (int) $tenant->getKey(),
        'is_enabled' => false,
        'provider' => 'microsoft',
    ]);

    $this->actingAs($user);
    $tenant->makeCurrent();
    Filament::setTenant($tenant, true);

    Livewire::test(ViewProviderConnection::class, ['record' => $connection->getKey()])
        ->assertActionVisible('edit')
        ->assertActionDisabled('edit')
        ->assertActionExists('edit', function (Action $action): bool {
            return $action->getTooltip() === UiTooltips::insufficientPermission();
        });
});
