<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CmsBundle\Form;

use Ferienpass\CmsBundle\Form\CompoundType\PostalAddressesType;
use Ferienpass\CmsBundle\Form\SimpleType\ContaoRequestTokenType;
use Ferienpass\CoreBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
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 UserPersonalDataType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('firstname', TextType::class, [
                'required' => true,
            ])
            ->add('lastname', TextType::class, [
                'required' => true,
            ])

            ->add('email', EmailType::class, [
                'attr' => ['placeholder' => 'email@beispiel.de'],
                'required' => true,
            ])

            ->add('phone', TelType::class, [
                'attr' => ['placeholder' => '030-00000'],
            ])
            ->add('mobile', TelType::class, [
                'attr' => ['placeholder' => '0172-0000000'],
            ])

            ->add('locale', ChoiceType::class, [
                'choices' => [
                    'Deutsch' => 'de',
                    'English' => 'en',
                    'العربية' => 'ar',
                    'Nederlands' => 'nl',
                    'Русский' => 'ru',
                    'Українська' => 'uk',
                    'Türkçe' => 'tr',
                    'Polski' => 'pl',
                    'Shqip' => 'sq',
                    'Kurmancî' => 'ku',
                    'Español' => 'es',
                    'Français' => 'fr',
                    'Português' => 'pt',
                    'Kiswahili' => 'sw',
                    'دری' => 'prs',
                    '中文' => 'zh',
                    'Српски' => 'sr',
                    'Hrvatski' => 'hr',
                    'Bosanski' => 'bs',
                ],
            ])

            ->add('postalAddresses', PostalAddressesType::class, [
                'label' => false,
            ])

            ->add('request_token', ContaoRequestTokenType::class)
            ->add('submit', SubmitType::class, [
                'label' => 'Daten speichern',
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => User::class,
            'required' => false,
            'label_format' => 'user.%name%',
            'translation_domain' => 'cms',
            'csrf_protection' => false,
            'validation_groups' => ['Default', 'email_unique'],
        ]);
    }
}
