<?php

namespace KupShop\ComponentsBundle\Twig\Components\Product\Reviews\Types;

use KupShop\ComponentsBundle\Twig\Components\Product\Reviews\Utils\WriteEntity;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class WriteFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('rating', ChoiceType::class, [
            'choices' => [
                'form.choice.5.stars' => 5,
                'form.choice.4.stars' => 4,
                'form.choice.3.stars' => 3,
                'form.choice.2.stars' => 2,
                'form.choice.1.star' => 1,
            ],
            'choice_label' => function () { return false; },
            'placeholder' => false,
            'expanded' => true,
        ])
            ->add('review', TextareaType::class, [
                'required' => false,
                'label' => 'form.label.review',
            ])
            ->add('positives', TextareaType::class, [
                'required' => false,
                'label' => 'form.label.positives',
            ])
            ->add('negatives', TextareaType::class, [
                'required' => false,
                'label' => 'form.label.negatives',
            ])
            ->add('email', TextType::class, [
                'required' => false,
                'label' => 'form.label.email',
            ])
            ->add('name', TextType::class, [
                'required' => false,
                'label' => 'form.label.name',
            ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => WriteEntity::class,
            'translation_domain' => 'products',
        ]);
    }
}
