<?php

namespace App\Filament\Blog\Resources\CategoryResource\Pages;

use App\Filament\Blog\Resources\CategoryResource;
use App\Filament\Resources\Pages\AuditedCreateRecord;

class CreateCategory extends AuditedCreateRecord
{
    protected static string $resource = CategoryResource::class;

    protected function getFormValidationRules(): array
    {
        return [
            'name_de' => 'required|string|max:255',
            'description_de' => 'nullable|string',
            'name_en' => 'nullable|string|max:255',
            'description_en' => 'nullable|string',
            'slug' => 'required|string|max:255|unique:blog_categories,slug',
            'is_visible' => 'boolean',
        ];
    }

    protected function store()
    {
        $state = $this->form->getState();
        $data = $state['data'] ?? $state;

        $data = \App\Filament\Blog\Resources\CategoryResource::mutateFormDataBeforeCreate($data);

        $this->record = static::getResource()::getModel()::create($data);
    }
}
