<?php

namespace App\Form;

use App\Entity\Post;

use App\Form\CategoryAutocompleteField;
use App\Form\TagAutocompleteField;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PostType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('title', TextType::class)
            ->add('date', DateType::class)
            ->add('description')
            ->add('text', TextareaType::class)
            ->add('category', CategoryAutocompleteField::class)
            ->add('tags', TagAutocompleteField::class, ['required' => false])
            ->add('url', TextType::class)
            ->add('published')
            ->add('save', SubmitType::class, ['label' => 'Save'])
        ;

        //$builder->get('tags')->resetViewTransformers();

    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Post::class,
            'validation_groups' => false,
        ]);
    }
}
