<?php

namespace App\Form\Type;

use App\Entity\Contrats;
use App\Entity\Customer;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
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;

class ContratsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('addressEvent',TextType::class,[
                'label' =>'Adresse',
                'required' => true,
            ])
            ->add('address2Event',TextType::class,[
                'label' =>'Adresse 2',
                'required' => false,
            ])
            ->add('address3Event',TextType::class,[
                'label' =>'Adresse 3',
                'required' => false,
            ])
            ->add('dateAt',DateTimeType::class,[
                'label' =>'Date',
                'widget' => 'single_text',
            ])
            ->add('endAt',DateTimeType::class,[
                'label' =>'Date de fin',
                'widget' => 'single_text',
            ])
            ->add('zipCodeEvent',TextType::class,[
                'label' =>'Code postal',
                'required' => true,
            ])
            ->add('townEvent',TextType::class,[
                'label' =>'Ville',
                'required' => true,
            ])
            ->add('customer',EntityType::class,[
                'label' => 'Client',
                'required' => true,
                'class' => Customer::class,
                // Utilisation d'une fonction anonyme pour concaténer Nom et Prénom
                'choice_label' => function (Customer $customer) {
                    return sprintf('%s - %s',
                        strtoupper($customer->getSurname()), // Nom en majuscules
                        $customer->getName()               // Prénom
                    );
                },
                'placeholder' => 'Sélectionnez un client...',

            ])
            ->add('type',ChoiceType::class,[
                'label' => 'Type',
                'required' => true,
                'choices' => [
                    'Anniversaire enfant' => 'Anniversaire enfant',
                    'Kermesse scolaire' => 'Kermesse scolaire',
                    'Fête communale' => 'Fête communale',
                    'Événement d\'entreprise' => 'Événement d\'entreprise',
                    'Mariage' => 'Mariage',
                    'Autre' => 'Autre'
                ]
            ])
            ->add('details',TextareaType::class,[
                'label' => 'Description',
                'required' => false,

            ])

            ->add('typeSol',ChoiceType::class,[
                'label' => 'Type de sol',
                'required' => true,
                'choices' => [
                    'Pelouse' => 'Pelouse',
                    'Béton' => 'Béton',
                    'Sable' => 'Sable',
                    'Gourdon' => 'Gourdon',
                    'Autre' => 'Autre'
                ]
            ])
            ->add('pente',ChoiceType::class,[
                'label' => 'Pente',
                'required' => true,
                'choices' => [
                    'Plat' => 'Plat',
                    'Léger' => 'Léger',
                    'Important' => 'Important',
                ]
            ])
            ->add('access',TextareaType::class,[
                'label' => 'Contraintes d\'accès',
                'required' => false,
            ])
            ->add('distancePower',NumberType::class,[
                'label' => 'Distance prise ↔ structure ',
                'required' => false,
            ])

            ->add('notes',TextareaType::class,[
                'label' => 'Notes',
                'required' => false,
            ])

        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefault('data_class',Contrats::class);
    }
}
