<?php

declare(strict_types=1);

use Filament\Facades\Filament;
use Illuminate\Support\Facades\Route;

it('does not keep a runtime TenantPanelProvider or tenant panel registration', function (): void {
    $registeredProviders = require base_path('bootstrap/providers.php');
    $tenantPanelProviders = collect($registeredProviders)
        ->filter(fn (string $provider): bool => str_contains($provider, 'TenantPanelProvider'))
        ->values();

    expect(file_exists(app_path('Providers/Filament/TenantPanelProvider.php')))->toBeFalse()
        ->and(file_exists(app_path('Filament/Providers/TenantPanelProvider.php')))->toBeFalse()
        ->and($tenantPanelProviders)->toBeEmpty()
        ->and(Filament::getPanel('tenant'))->toBeNull();
});

it('does not register active /admin/t routes', function (): void {
    $legacyRouteUris = collect(Route::getRoutes())
        ->map(fn ($route): string => ltrim((string) $route->uri(), '/'))
        ->filter(fn (string $uri): bool => preg_match('#^admin/t(?:/|$)#', $uri) === 1)
        ->values();

    expect($legacyRouteUris)->toBeEmpty();

    $this->get('/admin/t/example')->assertNotFound();
    $this->get('/admin/t/example/inventory-items')->assertNotFound();
});
