<?php

declare(strict_types=1);

namespace App\Filament\Resources\EvidenceSnapshotResource\Pages;

use App\Filament\Resources\EvidenceSnapshotResource;
use App\Support\Auth\Capabilities;
use App\Support\Rbac\UiEnforcement;
use Filament\Actions;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Pages\ListRecords;
use Filament\Schemas\Components\Section;

class ListEvidenceSnapshots extends ListRecords
{
    protected static string $resource = EvidenceSnapshotResource::class;

    protected function getHeaderActions(): array
    {
        return [
            UiEnforcement::forAction(
                Actions\Action::make('create_snapshot')
                    ->label('Create snapshot')
                    ->icon('heroicon-o-plus')
                    ->action(fn (array $data): mixed => EvidenceSnapshotResource::executeGeneration($data))
                    ->form([
                        Section::make('Snapshot options')
                            ->schema([
                                Toggle::make('allow_stale')
                                    ->label('Allow stale dimensions')
                                    ->default(false),
                            ]),
                    ]),
            )
                ->requireCapability(Capabilities::EVIDENCE_MANAGE)
                ->apply(),
        ];
    }
}
