<?php

namespace App\Filament\Resources\ReviewPackResource\Pages;

use App\Filament\Resources\ReviewPackResource;
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 ListReviewPacks extends ListRecords
{
    protected static string $resource = ReviewPackResource::class;

    protected function getHeaderActions(): array
    {
        return [
            UiEnforcement::forAction(
                Actions\Action::make('generate_pack')
                    ->label('Generate Pack')
                    ->icon('heroicon-o-plus')
                    ->action(function (array $data): void {
                        ReviewPackResource::executeGeneration($data);
                    })
                    ->form([
                        Section::make('Pack options')
                            ->schema([
                                Toggle::make('include_pii')
                                    ->label('Include PII')
                                    ->helperText('Include personally identifiable information in the export.')
                                    ->default(config('tenantpilot.review_pack.include_pii_default', true)),
                                Toggle::make('include_operations')
                                    ->label('Include operations')
                                    ->helperText('Include recent operation history in the export.')
                                    ->default(config('tenantpilot.review_pack.include_operations_default', true)),
                            ]),
                    ])
            )
                ->requireCapability(Capabilities::REVIEW_PACK_MANAGE)
                ->apply(),
        ];
    }
}
