<?php

namespace App\Form;

use App\Entity\User;
use App\Enums\CaseLevel;
use App\Enums\JobType;
use App\Enums\RateType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class EditUserFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', TextType::class, [
                'required' => true,
                'label' => 'Name',
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'Name',
                ],
            ])
            ->add('email', EmailType::class, [
                'required' => true,
                'label' => 'Email',
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'Email',
                ],
            ])
            ->add('workPhone', TextType::class)
            ->add('personalPhone', TextType::class)
            ->add('active', CheckboxType::class)
            ->add('caseWorker', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('caseManager', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('therapist', CheckboxType::class, [
                'mapped' => false
            ])
            ->add('su', CheckboxType::class, [
                'mapped' => false,
                'label' => 'Admin'
            ])
            ->add('rateType', EnumType::class, [
                'class' => RateType::class
            ])
            ->add('rate', NumberType::class)
            ->add('level', EnumType::class, [
                'class' => CaseLevel::class,
            ])
        ;
    }

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