<?php

namespace App\Form;

use App\Entity\Customer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CustomerAddType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('civ', ChoiceType::class, [
                'label' => 'Civilité',
                'choices' => [
                    'Monsieur' => 'M.',
                    'Madame' => 'Mme',
                ],
                'expanded' => false,
                'multiple' => false,
            ])
            ->add('surname', TextType::class, [
                'label' => 'Prénom',
                'attr' => ['placeholder' => 'ex: Jean'],
                'required' => true,
            ])
            ->add('name', TextType::class, [
                'label' => 'Nom',
                'attr' => ['placeholder' => 'ex: DUPONT'],
                'required' => true,
            ])
            ->add('type', ChoiceType::class, [
                'label' => 'Type de client',
                'choices' => [
                    'Particulier' => 'personal',
                    'Entreprise' => 'company',
                    'Association' => 'association',
                    'Mairie / Collectivité' => 'mairie',
                ],
            ])
            ->add('email', EmailType::class, [
                'label' => 'Adresse Email',
                'attr' => ['placeholder' => 'contact@exemple.fr'],
                'required' => true,
            ])
            ->add('phone', TelType::class, [ // TelType est plus adapté pour mobile
                'label' => 'Téléphone',
                'attr' => ['placeholder' => '06 .. .. .. ..'],
                'required' => true,
            ])
            ->add('siret', TextType::class, [
                'label' => 'Numéro SIRET',
                'required' => false,
                'attr' => ['placeholder' => '14 chiffres'],
                'help' => 'Obligatoire pour les entreprises et mairies',
            ])

            ->add('adresse', TextType::class, [
                'label' => 'Adresse',
                'required' => true,
                'mapped' => false,
            ])
            ->add('adresse2', TextType::class, [
                'label' => 'Adresse 2',
                'required' => false,
                'mapped' => false,
            ])
            ->add('adresse3', TextType::class, [
                'label' => 'Adresse 3',
                'required' => false,
                'mapped' => false,
            ])
            ->add('zipcode', TextType::class, [
                'label' => 'Code postale',
                'required' => true,
                'mapped' => false,
            ])
            ->add('city', TextType::class, [
                'label' => 'Ville',
                'required' => true,
                'mapped' => false,
            ])
            ->add('country', ChoiceType::class, [
                'label' => 'Pays',
                'required' => true,
                'mapped' => false,
                'choices' => [
                    'France' => 'fr',

                ]
            ])
        ;
    }

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