<?php

declare(strict_types=1);

namespace MauticPlugin\DealFlowBundle\Form\Type;

use MauticPlugin\DealFlowBundle\Entity\DealStage;
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 DealStageType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', TextType::class, [
                'label' => 'Stage name',
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'Proposal sent',
                ],
            ])
            ->add('slug', TextType::class, [
                'label' => 'Slug',
                'required' => false,
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'proposal-sent',
                ],
            ])
            ->add('sortOrder', IntegerType::class, [
                'label' => 'Sort order',
                'attr' => [
                    'class' => 'form-control',
                ],
            ])
            ->add('probability', IntegerType::class, [
                'label' => 'Probability (%)',
                'attr' => [
                    'class' => 'form-control',
                    'min' => 0,
                    'max' => 100,
                ],
            ])
            ->add('stageType', ChoiceType::class, [
                'label' => 'Stage type',
                'choices' => [
                    'Open' => 'open',
                    'Closed Won' => 'won',
                    'Closed Lost' => 'lost',
                ],
            ])
            ->add('isPublished', CheckboxType::class, [
                'label' => 'Published',
                'required' => false,
            ]);
    }

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