<?php

declare(strict_types=1);

namespace App\Filament\Resources\Reports\Pages;

use App\Filament\Resources\Reports\ReportResource;
use Filament\Actions\Action;
use Filament\Resources\Pages\CreateRecord;

class CreateReport extends CreateRecord
{
    protected static string $resource = ReportResource::class;

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

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

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

