<?php

namespace App\Form;

use App\Entity\Customer;
use App\Entity\Product;
use App\Repository\CategoryRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProductType extends AbstractType
{

    public function __construct(private readonly CategoryRepository $categoryRepository)
    {

    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $categoryList = [];
        foreach ($this->categoryRepository->findAll() as $category) {
            $categoryList[$category->getName()] = $category->getName();
        }
        $builder
            ->add('name',TextType::class,[
                'label' => 'Nom du produit',
                'required' => true,
            ])
            ->add('ref',TextType::class,[
                'label' => 'Reference du produit',
                'required' => true,
            ])
            ->add('description',TextareaType::class,[
                'label' => 'Description du produit',
                'required' => false,
            ])
            ->add('category',ChoiceType::class,[
                'label' => 'Catégorie du produit',
                'required' => true,
                'choices' => $categoryList,
            ])
            ->add('caution',NumberType::class,[
                'label' => 'Caution du produit',
                'required' => true,
                'html5' => true,
            ])
            ->add('priceDay',NumberType::class,[
                'label' => 'Prix journée',
                'required' => true,
                'html5' => true,
            ])
            ->add('priceSup',NumberType::class,[
                'required' => false,
                'html5' => true,
            ])

            ->add('dimW',NumberType::class,[
                'label' => 'Largeur',
                'required' => false,
                'html5' => true,
            ])
            ->add('dimP',NumberType::class,[
                'label' => 'Longeur',
                'required' => false,
                'html5' => true,
            ])
            ->add('dimH',NumberType::class,[
                'label' => 'Hauteur',
                'required' => false,
                'html5' => true,
            ])
            ->add('imageFile',FileType::class,[
                'label' => 'Image du produit',
                'required' => false,
            ])
        ;
    }

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