<?php

namespace App\Filament\Pages\AdminVerification\Actions;

use App\Enums\DecisionAdmin;
use App\Filament\Pages\AdminVerification\Actions\Concerns\CanProcessReview;
use App\Filament\Support\CheerfulNotification;
use Filament\Actions\Action;
use Filament\Forms\Components\Textarea;

class RejectAction extends Action
{
    use CanProcessReview;

    public static function getDefaultName(): ?string
    {
        return 'reject';
    }

    protected function setUp(): void
    {
        parent::setUp();

        $this->label('Tolak')
            ->color('danger')
            ->icon('heroicon-o-x-mark')
            ->size('sm')
            ->requiresConfirmation()
            ->modalHeading(fn () => CheerfulNotification::getByKey('actions.reject.title'))
            ->modalDescription(fn () => CheerfulNotification::getByKey('actions.reject.description'))
            ->modalSubmitActionLabel('Ya, Tolak')
            ->schema([
                Textarea::make('note')
                    ->label('Alasan Penolakan')
                    ->required()
                    ->placeholder('Jelaskan alasan pengajuan ditolak...')
                    ->autocomplete(false)
                    ->autofocus(),
            ])
            ->action(function (array $arguments, array $data): void {
                $this->processReview($arguments['id'], DecisionAdmin::REJECTED, $data['note']);
            });
    }
}
