<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\Security;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\Security\Model\LoginRequest;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class LoginType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('email', EmailType::class, [
                'label' => 'security.email.label',
                'attr' => [
                    'autocomplete' => 'username',
                ],
            ])
            ->add('password', PasswordType::class, [
                'label' => 'security.password.label',
                'always_empty' => false,
                'attr' => [
                    'autocomplete' => 'current-password',
                ],
            ])
            ->add('rememberMe', CheckboxType::class, [
                'label' => 'security.remember_me.label',
                'required' => false,
            ]);
    }

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