<?php

declare(strict_types=1);

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

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\Account\Model\AccountData;
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\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class AccountType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('email', EmailType::class, [
                'label' => 'shop.form.email',
                'attr' => [
                    'autocomplete' => 'email',
                ],
            ])
            ->add('marketingOptIn', CheckboxType::class, [
                'label' => 'security.marketing_opt_in.label',
                'required' => false,
                'translation_domain' => 'form',
            ])
            ->add('invoiceAddress', AccountAddressType::class, [
                'include_email' => true,
                'include_vat_id' => true,
                'include_different_address' => true,
            ])
            ->add('deliveryAddress', AccountAddressType::class, [
                'include_vat_id' => true,
            ]);
    }

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