<?php
/**
 * 2007-2023 PrestaShop
 *
 * 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.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 *
 *  @author    PrestaShop SA <contact@prestashop.com>
 *  @copyright 2007-2023 PrestaShop SA
 *  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 *  International Registered Trademark & Property of PrestaShop SA
 */
declare(strict_types=1);

namespace PrestaShop\Module\AgileMultisellerPro\Form\Configuration;

use PrestaShop\PrestaShop\Adapter\Category\CategoryDataProvider;
use PrestaShopBundle\Form\Admin\Type\CategoryChoiceTreeType;
use PrestaShopBundle\Form\Admin\Type\SwitchType;
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Translation\TranslatorInterface;

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

class Form extends TranslatorAwareType
{
    /**
     * @var CategoryDataProvider
     */
    private $categoryProvider;

    /**
     * @var int
     */
    private $languageId;

    public function __construct(TranslatorInterface $translator, array $locales, CategoryDataProvider $categoryDataProvider, $languageId)
    {
        $this->categoryProvider = $categoryDataProvider;
        $this->languageId = $languageId;

        parent::__construct($translator, $locales);
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add(
            'seller_terms',
            IntegerType::class,
            [
                'label' => $this->trans('Seller Terms & Conditions', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Please enter the CMS page ID for Seller Terms & Conditions. Enter "0" if there is no Seller Terms & Conditions.', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'product_image_number',
            IntegerType::class,
            [
                'label' => $this->trans('Limit product images number', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Please enter the max number of product images seller can upload, Enter "0" if you do not want to set limit.', 'Modules.Agilemultisellerpro.Module'),
                'attr' => [
                    'min' => 0,
                ],
            ]
        )->add(
            'customer_seller',
            SwitchType::class,
            [
                'label' => $this->trans('Allow customer to be a seller', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Allow customers to sign up for a seller\'s account and list products.', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'seller_approval',
            SwitchType::class,
            [
                'label' => $this->trans('Account Approval required', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Sellers registering from the front office is required to be approved/activated by Admin.', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'is_manufacturer',
            SwitchType::class,
            [
                'label' => $this->trans('Set a seller as the manufacturer (brand)', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Manufacturer (brand) will be shown in the products for visitors', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'is_supplier',
            SwitchType::class,
            [
                'label' => $this->trans('Set a seller as the supplier', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Supplier will be shown in the products for admin', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'allow_register_athome',
            SwitchType::class,
            [
                'label' => $this->trans('Apply this category as the default', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('If you want to allow seller to register product at store Home category', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'default_category',
            CategoryChoiceTreeType::class,
            [
                'label' => ' ',
                'translation_domain' => 'Modules.Agilemultisellerpro.Admin',
                'choices_tree' => $this->categoryProvider->getNestedCategories(null, $this->languageId, false),
                'multiple' => false,
                'required' => true,
                'help' => $this->trans('Set this category as the default in case the seller has specified an invalid category or empty', 'Modules.Agilemultisellerpro.Module'),
            ],
        )->add(
            'edit_category',
            SwitchType::class,
            [
                'label' => $this->trans('Allow seller creation categories', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Allow the seller to create a new category', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'seller_tab',
            SwitchType::class,
            [
                'label' => $this->trans('"Seller Info" tab', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Checking this box adds a new tab on the Product Detail page in the Front Office (store), for seller added products. This new tab displays the seller\'s information (i.e. address and phone number), as well as the seller\'s location in a Google Maps window if they so choose.', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'seller_info_gmap',
            SwitchType::class,
            [
                'label' => $this->trans('Google Maps', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Allow the Seller to indicate the coordinates of the pick-up point on Google Maps.', 'Modules.Agilemultisellerpro.Module'),
            ]
        )->add(
            'seller_info_gmap_key',
            TextType::class,
            [
                'label' => $this->trans('Google Maps API key', 'Modules.Agilemultisellerpro.Module'),
                'help' => $this->trans('Required if the use option "Google Maps" is enabled.', 'Modules.Agilemultisellerpro.Module'),
                'required' => false,
            ]
        );
    }
}
