<?php
/**
 * 2026 Paysera
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * @author Paysera <plugins@paysera.com>
 * @copyright 2026 Paysera
 * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
 * International Registered Trademark & Property of Paysera
 */

declare(strict_types=1);

namespace Paysera\PrestashopPayments\Form;

use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

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

final class AuthorizationFormType extends TranslatorAwareType
{
    /**
     * @param array<string, mixed> $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('client_id', TextType::class, [
                'label' => $this->trans('Client ID', 'Modules.Payserapayments.Global'),
                'help' => $this->trans(
                    'Enter the Client ID from your Paysera project settings',
                    'Modules.Payserapayments.Global'
                ),
                'required' => true,
                'constraints' => [
                    new NotBlank([
                        'message' => $this->trans(
                            'Client ID cannot be empty',
                            'Modules.Payserapayments.Global'
                        ),
                    ]),
                ],
            ])
            ->add('client_secret', TextType::class, [
                'label' => $this->trans('Client secret', 'Modules.Payserapayments.Global'),
                'help' => $this->trans(
                    'Enter the Client secret from your Paysera project settings',
                    'Modules.Payserapayments.Global'
                ),
                'required' => true,
                'attr' => [
                    'type' => 'password',
                    'class' => 'form-control password-toggle-field paysera-password-toggle__input',
                    'autocomplete' => 'current-password',
                ],
                'constraints' => [
                    new NotBlank([
                        'message' => $this->trans(
                            'Client secret cannot be empty',
                            'Modules.Payserapayments.Global'
                        ),
                    ]),
                ],
            ])
        ;
    }
}
