<?php

declare(strict_types=1);


namespace App\Filament\Resources\Posts\Pages;

use App\Filament\Resources\Posts\PostResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;

class EditPost extends EditRecord
{
    protected static string $resource = PostResource::class;

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

    protected function mutateFormDataBeforeSave(array $data): array
    {
        // 表单只包含部分 meta 键（插件注入的价格/会员标记等），合并保留其他插件写入的键（如解锁用户）
        if (array_key_exists('meta', $data)) {
            $data['meta'] = array_merge($this->record->meta ?? [], $data['meta'] ?? []);
        }

        return $data;
    }
}
