<?php

namespace KupShop\ComponentsBundle\Twig\Components\UserLogin;

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\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Type extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        if (findModule(\Modules::USERS, \Modules::SUB_USERS_PHONE_LOGIN)) {
            $builder->add('login', TextType::class, [
                'attr' => [
                    'placeholder' => 'form.placeholder.login.phone',
                ],
                'label' => 'form.label.login.phone',
            ]);
        } else {
            $builder->add('login', EmailType::class, [
                'attr' => [
                    'placeholder' => 'form.placeholder.login',
                ],
                'label' => 'form.label.login',
            ]);
        }

        $builder
            ->add('password', PasswordType::class, [
                'always_empty' => false,
                'attr' => [
                    'placeholder' => 'form.placeholder.password',
                ],
                'label' => 'form.label.password',
            ])
            ->add('Submit', SubmitType::class, [
                'attr' => ['class' => 'btn btn-block'],
                'label' => 'form.label.submit',
            ]);
    }

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