<?php

declare(strict_types=1);

namespace App\Filament\Resources\Reports\Pages;

use App\Filament\Resources\Reports\ReportResource;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Actions\ForceDeleteAction;
use Filament\Actions\RestoreAction;
use Filament\Resources\Pages\EditRecord;

class EditReport extends EditRecord
{
    protected static string $resource = ReportResource::class;

    protected function getHeaderActions(): array
    {
        return [
            DeleteAction::make(),
            ForceDeleteAction::make(),
            RestoreAction::make(),
        ];
    }

    protected function getFormActions(): array
    {
        return [
            Action::make('saveDraft')
                ->label('ذخیره پیش‌نویس')
                ->color('gray')
                ->action('saveDraft'),
            $this->getSaveFormAction()->label('ثبت گزارش'),
            $this->getCancelFormAction(),
        ];
    }

    public function saveDraft(): void
    {
        $this->form->fill(array_merge($this->form->getState(), ['status' => 'draft']));
        $this->save();
    }

    protected function getSavedNotificationTitle(): ?string
    {
        if ($this->getRecord() && $this->getRecord()->status === 'draft') {
            return 'گزارش به صورت پیش‌نویس ذخیره شد.';
        }
        return parent::getSavedNotificationTitle();
    }
}

