<?php

declare(strict_types=1);

namespace App\Filament\Resources\HealthReports\Pages;

use App\Filament\Resources\HealthReports\HealthReportResource;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Actions\ForceDeleteAction;
use Filament\Actions\RestoreAction;
use Filament\Resources\Pages\EditRecord;

class EditHealthReport extends EditRecord
{
    protected static string $resource = HealthReportResource::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();
    }
}
