<?php

namespace App\Form;

use App\Entity\Member;
use App\Entity\Referral;
use App\Entity\StandardNote;
use App\Enums\NoteLocation;
use App\Enums\NoteMethod;
use App\Enums\NoteStatus;
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 StandardNoteFormType 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('location', EnumType::class, [
                'class' => NoteLocation::class
            ])
            ->add('status', EnumType::class, [
                'class' => NoteStatus::class,
            ])
            ->add('note', null, [
                'required' => true,
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'Note',
                ],
            ])
            ->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' => StandardNote::class,
            'members' => [],
            'csrf_protection' => true,
            'csrf_field_name' => '_token',
            'csrf_token_id' => 'standard_note',
        ]);
    }
}
