<?php

namespace KupShop\ComponentsBundle\Twig\Components\Product\WatchDog\Types;

use KupShop\ComponentsBundle\Twig\Components\Product\WatchDog\Utils\Entity;
use KupShop\KupShopBundle\Context\CurrencyContext;
use KupShop\KupShopBundle\Context\UserContext;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class FormType extends AbstractType
{
    public function __construct(private readonly CurrencyContext $currencyContext, private readonly UserContext $userContext)
    {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('email', EmailType::class, [
                'required' => empty($this->userContext->getActiveId()),
                'label' => false,
            ])
            ->add('minPrice', MoneyType::class, [
                'currency' => $this->currencyContext->getActiveId(),
                'required' => false,
                'label' => false,
            ]);
    }

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