<?php

declare(strict_types=1);

namespace MauticPlugin\DealFlowBundle\Form\Type;

use MauticPlugin\DealFlowBundle\Entity\DealField;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class DealFieldType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('label', TextType::class, [
                'label' => 'Field label',
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'Customer tier',
                ],
            ])
            ->add('alias', TextType::class, [
                'label' => 'API alias',
                'required' => false,
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'customer_tier',
                ],
            ])
            ->add('fieldType', ChoiceType::class, [
                'label' => 'Field type',
                'choices' => DealField::getTypeChoices(),
                'attr' => [
                    'class' => 'form-control',
                ],
            ])
            ->add('sortOrder', IntegerType::class, [
                'label' => 'Sort order',
                'attr' => [
                    'class' => 'form-control',
                ],
            ])
            ->add('isRequired', CheckboxType::class, [
                'label' => 'Required on deals',
                'required' => false,
            ])
            ->add('showInList', CheckboxType::class, [
                'label' => 'Show in deal list',
                'required' => false,
            ])
            ->add('isActive', CheckboxType::class, [
                'label' => 'Active',
                'required' => false,
            ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => DealField::class,
        ]);
    }
}
