<?php

declare(strict_types=1);

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

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\Security\Model\RegisterConfirmRequest;
use Symfony\Component\Form\AbstractType;
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 RegisterConfirmType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('email', EmailType::class, [
                'label' => 'security.email.label',
                'attr' => [
                    'autocomplete' => 'username',
                ],
            ])
            ->add('plainPassword', PasswordType::class, [
                'label' => 'security.password.label',
                'always_empty' => false,
                'attr' => [
                    'autocomplete' => 'new-password',
                ],
            ])
            ->add('passwordConfirmation', PasswordType::class, [
                'label' => 'security.password_confirmation.label',
                'always_empty' => false,
                'attr' => [
                    'autocomplete' => 'new-password',
                ],
            ]);
    }

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