<?php


namespace AutoAdmin\Bundle\Admin\Form\Type;


use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProfileType extends AbstractType
{
    public function configureOptions(OptionsResolver $resolver)
    {
        parent::configureOptions($resolver);
        $resolver->setDefaults(
            [
                'label' => false,
                'translation_domain' => 'aa_admin',
            ]
        );
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);

        $builder->add('username', TextType::class, ['label' => 'admin_profile.username', 'empty_data' => '',]);
        $builder->add('email', EmailType::class, ['label' => 'admin_profile.email',]);
        $builder->add(
            'oldPassword',
            PasswordType::class,
            ['label' => 'admin_profile.old_password', 'mapped' => false,]
        );
        $builder->add(
            'plainPassword',
            RepeatedType::class,
            [
                'type' => PasswordType::class,
                'invalid_message' => 'The password fields must match.',
                'options' => ['attr' => ['class' => 'password-field']],
                'required' => true,
                'first_options' => ['label' => 'admin_profile.new_password'],
                'second_options' => ['label' => 'admin_profile.new_password_repeat'],
            ]
        );
    }

    public function getParent(): string
    {
        return FormType::class;
    }
}