<?php

namespace App\Form;

use App\Entity\IndividualData\IndividualData;
use App\Entity\Territory\Territory;
use Lc\PietroBundle\Form\Revolt\RevoltType;
use Lc\PietroBundle\Form\Dream\DreamType;
use Lc\PietroBundle\Form\ProjectInspiring\ProjectInspiringType;
use Lc\PietroBundle\Form\ProjectBoost\ProjectBoostType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class IndividualDataForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('territory', EntityType::class, [
                'label' => 'form.field.territory.label',
                'translation_domain' => 'frontend',
                'class' => Territory::class,
                'expanded' => true,
                'multiple' => false,
            ])
            ->add('revolt', CollectionType::class, [
                'label' => 'form.field.revolt.label',
                'translation_domain' => 'frontend',
                'entry_type' => RevoltType::class,
                'entry_options' => [
                    'context' => $options['context'],
                    'label' => false,
                ],
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
            ])
            ->add('dream', CollectionType::class, [
                'label' => 'form.field.dream.label',
                'translation_domain' => 'frontend',
                'entry_type' => DreamType::class,
                'entry_options' => [
                    'context' => $options['context'],
                    'label' => false,
                ],
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
            ])
            ->add('projectBoost', CollectionType::class, [
                'label' => 'form.field.projectBoost.label',
                'translation_domain' => 'frontend',
                'entry_type' => ProjectBoostType::class,
                'entry_options' => [
                    'context' => $options['context'],
                    'label' => false,
                ],
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
            ])
            ->add('projectInspiring', CollectionType::class, [
                'label' => 'form.field.projectinspiring.label',
                'translation_domain' => 'frontend',
                'entry_type' => ProjectInspiringType::class,
                'entry_options' => [
                    'context' => $options['context'],
                    'label' => false,
                ],
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
            ])
            ->add('save', SubmitType::class, [
                'attr' => ['class' => 'save button-yellow'],
                'label' => 'ENVOYER'
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'data_class' => IndividualData::class,
                "context" => "backend"
            ]
        );
    }
}
