<?php

declare(strict_types=1);

use App\Filament\Pages\Monitoring\Alerts;
use App\Support\Workspaces\WorkspaceContext;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

it('keeps alerts as a quiet overview with downstream drilldown entry points', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    Filament::setTenant(null, true);

    $this->actingAs($user)
        ->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
        ->followingRedirects()
        ->get('/admin/alerts')
        ->assertOk()
        ->assertSee('Alert targets')
        ->assertSee('Alert rules')
        ->assertSee('Alert deliveries')
        ->assertDontSee('Focused review lane')
        ->assertDontSee('Follow-up lane');
});

it('surfaces origin context quietly on the alerts overview', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    Filament::setTenant(null, true);

    session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id);
    setAdminPanelContext();

    Livewire::withQueryParams([
        'nav' => [
            'source_surface' => 'backup_set.detail_section',
            'canonical_route_name' => 'admin.alerts.overview',
            'back_label' => 'Back to backup set',
            'back_url' => '/admin/tenant/backup-sets/1',
        ],
    ])
        ->actingAs($user)
        ->test(Alerts::class)
        ->assertSee('Back to backup set')
        ->assertSee('/admin/tenant/backup-sets/1', false);
});
