<?php
/**
 * Copyright since 2025 InPost S.A.
 *
 * For the full license information, please view the LICENSE file bundled with the module.
 *
 * @author InPost S.A.
 * @copyright since 2025 InPost S.A.
 * @license MIT
 */

declare(strict_types=1);

namespace InPost\International\Common\Form\Type;

use InPost\International\Common\DTO\ContactDetails;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;

if (!defined('_PS_VERSION_')) {
    exit;
}

final class ContactDetailsType extends AbstractType
{
    /**
     * @var TranslatorInterface
     */
    private $translator;

    public function __construct(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('companyName', TextType::class, [
                'required' => false,
                'label' => $this->translator->trans('Company', [], 'Admin.Global'),
            ])
            ->add('firstName', TextType::class, [
                'label' => $this->translator->trans('First name', [], 'Admin.Global'),
            ])
            ->add('lastName', TextType::class, [
                'label' => $this->translator->trans('Last name', [], 'Admin.Global'),
            ])
            ->add('email', EmailType::class, [
                'label' => $this->translator->trans('Email', [], 'Admin.Global'),
            ])
            ->add('phone', PhoneType::class, [
                'label' => $this->translator->trans('Phone', [], 'Admin.Global'),
            ]);
    }

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