<?php

namespace AutoAdmin\Bundle\Admin\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ExportType extends AbstractType
{
    /**
     * @inheritDoc
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $data = [];

        foreach ($options['data_fields'] as $field) {
            $data[$field['label']] = $field['property'];
        }

        $builder
            ->add('fields', ChoiceType::class, [
                'label' => false,
                'choices'  => $data,
                'multiple' => true,
                'required' => false,
                'attr' => [
                    'class' => 'aa-ft-rich-entity form-control choices__input',
                ],
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => null,
            'data_fields' => null,
        ]);
    }
}