<?php

declare(strict_types=1);

namespace App\Form\Finance;

use App\Entity\TypeFrais;
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\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class TypeFraisType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('code', TextType::class, ['label' => 'Code', 'attr' => ['placeholder' => 'INSCRIPTION']])
            ->add('libelle', TextType::class, ['label' => 'Libellé'])
            ->add('description', TextareaType::class, ['label' => 'Description', 'required' => false, 'attr' => ['rows' => 3]])
            ->add('nature', ChoiceType::class, [
                'label' => 'Nature',
                'choices' => [
                    'Inscription' => TypeFrais::NATURE_INSCRIPTION,
                    'Réinscription' => TypeFrais::NATURE_REINSCRIPTION,
                    'Annuel' => TypeFrais::NATURE_ANNUEL,
                    'Mensuel' => TypeFrais::NATURE_MENSUEL,
                    'Document' => TypeFrais::NATURE_DOCUMENT,
                    'Personnalisé' => TypeFrais::NATURE_PERSONNALISE,
                    'Autre' => TypeFrais::NATURE_AUTRE,
                ],
            ])
            ->add('periodicite', ChoiceType::class, [
                'label' => 'Périodicité',
                'required' => false,
                'placeholder' => 'Choisir',
                'choices' => [
                    'Unique' => TypeFrais::PERIODICITE_UNIQUE,
                    'Annuelle' => TypeFrais::PERIODICITE_ANNUELLE,
                    'Mensuelle' => TypeFrais::PERIODICITE_MENSUELLE,
                    'Personnalisée' => TypeFrais::PERIODICITE_PERSONNALISEE,
                ],
            ])
            ->add('montantDefaut', MoneyType::class, ['label' => 'Montant par défaut', 'required' => false, 'currency' => 'XAF', 'divisor' => 1])
            ->add('ordre', IntegerType::class, ['label' => 'Ordre'])
            ->add('actif', CheckboxType::class, ['label' => 'Actif', 'required' => false]);
    }

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