<?php

namespace App\Form;

use App\Entity\CompanyDocument;
use App\Entity\Member;
use App\Enums\GenderType;
use App\Enums\RaceType;
use App\Enums\RelationshipType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MemberFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $docs = $options['docs'];
        $builder
            ->add('lastName', null, ['required' => true])
            ->add('firstName', null, ['required' => true])
            ->add('personalId', null, ['required' => true])
            ->add('dob', DateType::class, [
                'widget' => 'single_text',
                'required' => true
            ])
            ->add('emergencyContact')
            ->add('phone')
            ->add('dayPhone')
            ->add('eveningPhone')
            ->add('cellPhone')
            ->add('email', EmailType::class)
            ->add('school')
            ->add('address')
            ->add('city')
            ->add('state')
            ->add('zip')
            ->add('maritalStatus')
            ->add('relationship', EnumType::class, [
                'class' => RelationshipType::class,
                'required' => true
            ])
            ->add('gender', EnumType::class, [
                'class' => GenderType::class,
                'required' => true
            ])
            ->add('race', EnumType::class, [
                'class' => RaceType::class
            ])
            ->add('language')
            ->add('isChild', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('isParent', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('isAdultChild', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('isLegalGuardian', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('parentsLiveTogether', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('dcsApproved', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('docs', EntityType::class, [
                'class' => CompanyDocument::class,
                'choices' => $docs,
                'multiple' => true,
                'expanded' => true,
                'choice_label' => 'title',
                'mapped' => false,
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Member::class,
            'docs' => [],
            'csrf_protection' => true,
            'csrf_field_name' => '_token',
            'csrf_token_id' => 'member',
        ]);
    }
}
