<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin;

use CpCreation\VitiCore\Commerce\Catalog\Model\CatalogConfiguration;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class CatalogConfigurationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('enabled', CheckboxType::class, [
                'label' => 'commerce_catalog.admin.enabled',
                'help' => 'commerce_catalog.admin.enabled_help',
                'required' => false,
            ])
            ->add('monitoringEnabled', CheckboxType::class, [
                'label' => 'commerce_catalog.admin.monitoring_enabled',
                'help' => 'commerce_catalog.admin.monitoring_enabled_help',
                'required' => false,
            ])
            ->add('hubUrl', UrlType::class, [
                'label' => 'commerce_catalog.admin.hub_url',
                'help' => 'commerce_catalog.admin.hub_url_help',
                'required' => false,
                'default_protocol' => 'https',
                'attr' => [
                    'autocomplete' => 'off',
                    'placeholder' => 'https://commerce.example.com',
                ],
            ]);
    }

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