<?php

namespace KupShop\ComponentsBundle\Twig\Components\ContactForm\Types;

use KupShop\ComponentsBundle\Twig\Components\ContactForm\Utils\Entity;
use KupShop\KupShopBundle\Context\UserContext;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
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 FormType extends AbstractType
{
    public function __construct(private readonly UserContext $userContext)
    {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', TextType::class, [
                'label' => 'form.label.name',
                'required' => !empty($this->userContext->getActiveId()),
            ])
            ->add('surname', TextType::class, [
                'label' => 'form.label.surname',
                'required' => !empty($this->userContext->getActiveId()),
            ])
            ->add('email', EmailType::class, [
                'label' => 'form.label.email',
                'required' => !empty($this->userContext->getActiveId()),
            ])
            ->add('phone', TextType::class, [
                'label' => 'form.label.phone',
                'required' => false,
            ])
            ->add('message', TextareaType::class, [
                'label' => 'form.label.message',
                'required' => true,
            ])
            ->add('news', CheckboxType::class, [
                'label' => 'lpg.get.news',
                'required' => false,
            ])
            ->add('attachment', FileType::class, [
                'label' => 'form.attachment.file',
                'multiple' => true,
                'mapped' => false,
                'required' => false,
            ]);
    }

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