<?php

namespace AutoAdmin\Bundle\Admin\Form;

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

class ExportType extends AbstractType
{
    /**
     * @inheritDoc
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $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): void
    {
        $resolver->setDefaults([
            'data_class' => null,
            'data_fields' => null,
        ]);
    }
}
