<?php

namespace App\Filament\Pages\AdminVerification\Actions;

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

class RevisionAction extends Action
{
    use CanProcessVerificationReview;

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

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

        $this->label('Minta Revisi')
            ->authorize(fn (): bool => auth()->user()?->can('Revision:AdminVerification'))
            ->color('warning')
            ->icon('heroicon-o-pencil-square')
            ->size('sm')
            ->link()
            ->modalHeading(fn () => CheerfulNotification::getByKey('actions.revision.title'))
            ->modalDescription(fn () => CheerfulNotification::getByKey('actions.revision.description'))
            ->schema([
                Textarea::make('note')
                    ->label('Catatan Revisi')
                    ->required()
                    ->placeholder('Jelaskan bagian yang perlu diperbaiki...')
                    ->autocomplete(false)
                    ->autofocus(),
            ])
            ->action(function (array $arguments, array $data): void {
                $this->processReview($arguments['id'], DecisionAdmin::NEED_REVISION, $data['note']);
            })
            ->modalWidth(Width::Large);
    }
}
