<?php

namespace Lc\SovBundle\Form\Ticket;

use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Model\Ticket\TicketMessageInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\File;

class TicketMessageType extends AbstractType
{
    protected EntityManagerInterface $entityManager;

    public function __construct(EntityManagerInterface $entityManager)
    {
        $this->entityManager = $entityManager;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
                ->add('message', TextareaType::class, [
                        'label' => 'entity.TicketMessage.fields.message',
                        'translation_domain' => 'admin',
                ])
                ->add('image', FileType::class, [
                        'label' => 'Photo',
                        'mapped' => false,
                        'required' => false,
                        'constraints' => [
                                new File([
                                                 'maxSize' => '2048k',
                                                 'mimeTypes' => [
                                                         'image/png',
                                                         'image/jpeg',
                                                         'image/jpg',
                                                         'image/gif',
                                                 ],
                                                 'mimeTypesMessage' => "Mauvais format d'image (formats acceptés : jpeg, png, gif)",
                                         ])
                        ],
                ])
                ->add('closeTicket', CheckboxType::class, [
                        'label' => 'entity.TicketMessage.fields.closeTicket',
                        'translation_domain' => 'admin',
                        'required' => false,
                        'mapped' => false,
                ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
                                       'data_class' => $this->entityManager->getEntityName(TicketMessageInterface::class),
                               ]);
    }
}
