<?php

namespace App\Form;

use App\Entity\Member;
use App\Entity\VisitNote;
use App\Enums\NoteLocation;
use App\Enums\NoteMethod;
use App\Enums\NoteStatus;
use App\Enums\VisitQualityLevel;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class VisitNoteFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $members = $options['members'];

        $builder
            ->add('date', null, [
                'widget' => 'single_text',
            ])
            ->add('startTime', null, [
                'widget' => 'single_text',
            ])
            ->add('endTime', null, [
                'widget' => 'single_text',
            ])
            ->add('status', EnumType::class, [
                'class' => NoteStatus::class
            ])
            ->add('location', EnumType::class, [
                'class' => NoteLocation::class
            ])
            ->add('narrative')
            ->add('strengths')
            ->add('issues')
            ->add('recommendation')
            ->add('parentalRole', EnumType::class, [
                'class' => VisitQualityLevel::class
            ])
            ->add('childDevelopment', EnumType::class, [
                'class' => VisitQualityLevel::class
            ])
            ->add('appropriateResponse', EnumType::class, [
                'class' => VisitQualityLevel::class
            ])
            ->add('childAheadOfSelf', EnumType::class, [
                'class' => VisitQualityLevel::class
            ])
            ->add('showsEmpathy', EnumType::class, [
                'class' => VisitQualityLevel::class
            ])
            ->add('childFocused', EnumType::class, [
                'class' => VisitQualityLevel::class
            ])
            ->add('members', EntityType::class, [
                'class' => Member::class,
                'choices' => $members,
                'multiple' => true,
                'expanded' => true,
                'choice_label' => 'name',
            ])
            ->add('method', EnumType::class, [
                'class' => NoteMethod::class
            ])
        ;
    }

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