<?php

namespace Lc\SovBundle\Form\User;

use Lc\SovBundle\DataTransformer\FileManagerTypeToDataTransformer;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Model\File\FileInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Translation\TranslatableMessage;

class ProfileFormType extends AbstractType
{
    protected $em;
    protected $translatorAdmin;

    public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin)
    {
        $this->em = $em;
        $this->translatorAdmin = $translatorAdmin;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $entityName = $this->em->getEntityName(UserInterface::class);

        $builder->add(
                'firstname',
                TextType::class,
                [
                        'label' => 'entity.default.fields.firstname',
                        'translation_domain' => 'admin',
                ]
        );

        $builder->add(
                'lastname',
                TextType::class,
                [
                        'label' => 'entity.default.fields.lastname',
                        'translation_domain' => 'admin',
                ]
        );

        $builder->add(
                'email',
                EmailType::class,
                [
                        'label' => 'entity.default.fields.email',
                        'translation_domain' => 'admin',
                ]
        );

        if (property_exists($entityName, 'phone')) {
            $builder->add(
                    'phone',
                    TextType::class,
                    [
                            'label' => 'entity.default.fields.phone',
                            'translation_domain' => 'admin',
                    ]
            );
        }
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
                [
                        'data_class' => $this->em->getEntityName(UserInterface::class),
                ]
        );
    }
}
