<?php

namespace App\Form;

use App\Entity\Client;
use App\Entity\Client\Department;
use App\Entity\ClientContact;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ClientContactType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('client', EntityType::class, [
                'label' => 'Client',
                'class' => Client::class,
                'choice_value' => 'id',
                'choice_label' => 'title',
            ])
            ->add('name', TextType::class, [
                'label' => 'Name',
                'required' => false,
            ])
            ->add('phone', TextType::class, [
                'label' => 'Phone',
                'required' => false,
            ])
            ->add('mobile', TextType::class, [
                'label' => 'Mobile',
                'required' => false,
            ])
            ->add('email', EmailType::class, [
                'label' => 'Email',
                'required' => false,
            ])
            ->add('departments', EntityType::class, [
                'class' => Department::class,
                'choice_label' => 'title',
                'by_reference' => false,
                'multiple' => true,
            ])
            ->add('main', ChoiceType::class, [
                'label' => 'Is Main?',
                'choices' => ['No' => 0, 'Yes' => 1],
                'required' => false,
                'empty_data' => '0',
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => ClientContact::class,
            'allow_extra_fields' => true,
            'csrf_protection' => false,
        ]);
    }
}
