<?php

namespace App\Filament\Resources\GuideResource\Pages;

use App\Filament\Resources\GuideResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditGuide extends EditRecord
{
    protected static string $resource = GuideResource::class;

    protected function getHeaderActions(): array
    {
        return [
            \Filament\Actions\Action::make('managePages')
                ->label('编辑指引')
                ->icon('heroicon-o-queue-list')
                ->url(fn() => GuideResource::getUrl('manage-pages', ['record' => $this->record])),
            Actions\DeleteAction::make()->label('删除'),
        ];
    }

    protected function mutateFormDataBeforeSave(array $data): array
    {
        if ($data['status'] === 'published' && !$this->record->published_at) {
            $data['published_at'] = now();
        }

        return $data;
    }
}
