<?php
/**
 * _             _       _
 * | |____      _| | __ _| |__
 * | '_ \ \ /\ / / |/ _` | '_ \
 * | |_) \ V  V /| | (_| | |_) |
 * |_.__/ \_/\_/ |_|\__,_|_.__/.
 *
 * @author    Bwlab di Luigi Massa <info@bwlab.it>
 * @copyright since 2014 Bwlab
 * @license   proprietary
 */

declare(strict_types=1);

namespace Bwlab\Withdrawal\Form;

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

use Bwlab\Withdrawal\Configuration\WithdrawalTextDataConfiguration;
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;

class WithdrawalConfigurationFormType extends TranslatorAwareType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add(WithdrawalTextDataConfiguration::ENABLED, CheckboxType::class, [
                'label' => $this->trans('Enable withdrawal function', 'Modules.Bwwithdrawal.Admin', []),
                'required' => false,
            ])
            ->add(WithdrawalTextDataConfiguration::DEFAULT_DAYS, IntegerType::class, [
                'label' => $this->trans('Default withdrawal days', 'Modules.Bwwithdrawal.Admin', []),
                'help' => $this->trans('Number of days from reference date (default: 14)', 'Modules.Bwwithdrawal.Admin', []),
                'attr' => ['min' => 1, 'max' => 365],
            ])
            ->add(WithdrawalTextDataConfiguration::DATE_REF, ChoiceType::class, [
                'label' => $this->trans('Reference date', 'Modules.Bwwithdrawal.Admin', []),
                'choices' => [
                    $this->trans('Order date', 'Modules.Bwwithdrawal.Admin', []) => 'order',
                    $this->trans('Delivery date', 'Modules.Bwwithdrawal.Admin', []) => 'delivery',
                ],
            ])
            ->add(WithdrawalTextDataConfiguration::MERCHANT_EMAIL, EmailType::class, [
                'label' => $this->trans('Merchant notification email', 'Modules.Bwwithdrawal.Admin', []),
            ])
            ->add(WithdrawalTextDataConfiguration::NOTICE_IT, TextareaType::class, [
                'label' => $this->trans('Pre-contractual notice (IT)', 'Modules.Bwwithdrawal.Admin', []),
                'required' => false,
                'attr' => ['rows' => 5],
            ])
            ->add(WithdrawalTextDataConfiguration::NOTICE_EN, TextareaType::class, [
                'label' => $this->trans('Pre-contractual notice (EN)', 'Modules.Bwwithdrawal.Admin', []),
                'required' => false,
                'attr' => ['rows' => 5],
            ]);
    }
}
