<?php

/*
 * This file is part of the VitiCore 2.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

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

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\EventListener\AddErrorMessageValidationListener;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\RecaptchaType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

final class ContactType extends AbstractType
{
    public function __construct(private readonly AddErrorMessageValidationListener $addErrorMessageValidationListener)
    {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('lastname', TextType::class, [
                'required' => true,
                'label' => false,
                'attr' => ['placeholder' => 'contact.form.name', 'autocomplete' => 'name'],
                'constraints' => [new NotBlank()],
            ])
            ->add('phone', TextType::class, [
                'required' => true,
                'label' => false,
                'attr' => ['placeholder' => 'contact.form.phone', 'autocomplete' => 'phone'],
                'constraints' => [new NotBlank()],
            ])
            ->add('email', EmailType::class, [
                'required' => true,
                'label' => false,
                'attr' => ['placeholder' => 'contact.form.email', 'autocomplete' => 'email'],
                'constraints' => [new NotBlank()],
            ])
            ->add('message', TextareaType::class, [
                'required' => true,
                'label' => false,
                'attr' => ['placeholder' => 'contact.form.message', 'rows' => 8],
                'constraints' => [new NotBlank()],
            ])
            ->add(
                'g_recaptcha_response', RecaptchaType::class
            );

        $builder->addEventSubscriber($this->addErrorMessageValidationListener);
    }
}
