<?php

use App\Filament\Pages\Tenancy\RegisterTenant;
use App\Filament\Resources\TenantResource;
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('tenant'));

    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(TenantResource::canCreate())->toBeFalse();
});
