<?php

namespace Lc\ShopBundle\Form\Backend\Common;

use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Lc\ShopBundle\Context\AddressInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\NotBlank;

class AddressType extends AbstractType
{
        protected $em;

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

        public function buildForm(FormBuilderInterface $builder, array $options)
        {
                $builder
                        ->add('title', TextType::class, ['label' => 'Titre'])
                        ->add('type', ChoiceType::class, [
                                'label' => 'Type',
                                'choices' => [
                                        '--' => '',
                                        'Particulier' => 'individual',
                                        'Personne morale' => 'legal-person',
                                ]
                        ])
                        ->add('civility', ChoiceType::class, [
                                'label' => 'Civilité',
                                'required' => false,
                                'choices' => [
                                        '--' => '',
                                        'Femme' => 1,
                                        'Homme' => 0,
                                ],
                        ])
                        ->add('lastname', TextType::class, ['required' => false])
                        ->add('firstname', TextType::class, ['required' => false])
                        ->add('address', TextareaType::class)
                        ->add('zip', TextType::class)
                        ->add('city', TextType::class)
                        ->add('country', TextType::class)
                        ->add('phone', TextType::class, ['required' => false])
                        ->add('company', TextType::class, ['required' => false])
                        ->add('siret', TextType::class, ['required' => false])
                        ->add('tva', TextType::class, ['required' => false]);
        }

        public function configureOptions(OptionsResolver $resolver)
        {
                $resolver->setDefaults([
                        'label' => false,
                        'data_class' => $this->em->getClassMetadata(AddressInterface::class)->getName()
                ]);
        }
}
