<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site;

use CpCreation\VitiCore\Marketing\DTO\ProductReviewSubmission;
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\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class ProductReviewSubmissionType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('productId', ChoiceType::class, [
                'label' => 'marketing.review.form.product',
                'choices' => $options['product_choices'],
                'placeholder' => 'marketing.review.form.product_placeholder',
            ])
            ->add('rating', ChoiceType::class, [
                'label' => 'marketing.review.form.rating',
                'choices' => [
                    'marketing.review.form.rating_5' => 5,
                    'marketing.review.form.rating_4' => 4,
                    'marketing.review.form.rating_3' => 3,
                    'marketing.review.form.rating_2' => 2,
                    'marketing.review.form.rating_1' => 1,
                ],
            ])
            ->add('comment', TextareaType::class, [
                'label' => 'marketing.review.form.comment',
                'attr' => ['rows' => 7],
            ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => ProductReviewSubmission::class,
            'translation_domain' => 'messages',
            'product_choices' => [],
        ]);
        $resolver->setAllowedTypes('product_choices', 'array');
    }
}
