<?php

namespace App\Form;

use App\Entity\CommunityResource;
use App\Enums\County;
use App\Enums\ResourceType;
use App\Enums\State;
use Symfony\Component\Form\AbstractType;
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\Extension\Core\Type\TimeType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ResourceFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', TextType::class, [
                'required' => true,
            ])
            ->add('address', TextType::class, [
                'required' => true,
            ])
            ->add('address2')
            ->add('city', TextType::class, [
                'required' => true,
            ])
            ->add('state', EnumType::class, [
                'class' => State::class,
            ])
            ->add('zip', NumberType::class)
            ->add('county', EnumType::class, [
                'class' => County::class,
            ])
            ->add('phone')
            ->add('email', EmailType::class)
            ->add('url', UrlType::class)
            ->add('monOpen', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('monClose', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('tueOpen', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('tueClose', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('wedOpen', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('wedClose', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('thuOpen', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('thuClose', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('friOpen', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('friClose', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('satOpen', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('satClose', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('sunOpen', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('sunClose', TimeType::class, [
                'widget' => 'single_text',
            ])
            ->add('notes')
            ->add('type', EnumType::class, [
                'class' => ResourceType::class,
                'expanded' => true,
                'multiple' => true,

            ])
            ->add('servicesAvailable')
        ;
    }

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