<?php

use App\Filament\Pages\Tenancy\RegisterTenant;
use App\Filament\Resources\ManagedEnvironmentResource;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

test('readonly users cannot access tenant registration', function () {
    [$user] = createUserWithTenant(role: 'readonly');

    $this->actingAs($user);

    Filament::setCurrentPanel(Filament::getPanel('admin'));

    expect(RegisterTenant::canView())->toBeFalse();

    Livewire::actingAs($user)
        ->test(RegisterTenant::class)
        ->assertStatus(404);

    Filament::setCurrentPanel(null);
});

test('readonly users cannot create tenants via CRUD', function () {
    [$user] = createUserWithTenant(role: 'readonly');

    $this->actingAs($user);

    expect(ManagedEnvironmentResource::canCreate())->toBeFalse();
});
