<?php

namespace PrestaShop\Module\LCVPrestaTheme\Forms;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use PrestaShopBundle\Form\Admin\Type\SwitchType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ColorType;
use Context;
use Category;


class MenuParentType extends AbstractType{

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {

        $categories_parent = Category::getCategories(
            Context::getContext()->language->id,
            true, // active
            false // id_parent = 1
        );

        $choices = [];
        foreach ($categories_parent as $category) {
            $choices[$category['name']] = $category['id_category'];
        }
        
        $builder
        ->add('isVisible',SwitchType::class, [
            'required' => false,
            'label' => 'Activer la visibilité',
        ])

        ->add('menu_type', ChoiceType::class, [
                'label'    => 'Type de menu',
                'choices'  => [
                    'Catégorie PrestaShop' => 'category',
                    'Lien personnalisé'    => 'custom',
                    'Onglet Marques (A-Z)' => 'brand',
                ],
                'multiple' => false,
                'attr'     => ['class' => 'menu-type-toggle'],
        ])

        ->add('menu', ChoiceType::class, [
            'label' => 'Sélectionner la catégorie parent du menu ',
            'multiple' => false,
            'choices' => $choices,
            'required' => true,
            'attr' => ['class' => 'menu-field-category'],
        ])

        ->add('custom_label', TextType::class, [
                'label'    => 'Texte du lien',
                'required' => false,
                'empty_data' => '',
                'attr' => ['style' => 'display:none', 'class' => 'menu-field-custom' , 'placeholder' => 'Titre personnalisé'],
                
        ])
        ->add('custom_url', TextType::class, [
                'label'    => 'URL du lien',
                'empty_data' => '',
                'required' => false,
                'attr' => ['style' => 'display:none', 'class' => 'menu-field-custom', 'placeholder' => 'https://...'],
        ])

        ->add('image', FileType::class, [
            'label'    => 'Image (optionnelle)',
            'required' => false,
            'mapped'   => false,
            'attr'     => ['class' => 'menu-field-custom', 'style' => 'display:none'],
        ])

        ->add('brand_label', TextType::class, [
            'label'      => 'Libellé de l\'onglet',
            'required'   => false,
            'empty_data' => 'Marques',
            'attr'       => ['style' => 'display:none', 'class' => 'menu-field-brand', 'placeholder' => 'Marques'],
        ])

        ->add('color', ColorType::class, [
            'label'      => 'Couleur du lien',
            'required'   => false,
            'help'       => 'Couleur du texte de ce lien parent dans le menu.',
            'attr'       => ['class' => 'color-picker', 'data-hex' => 'true'],
        ])

        ->add('fontWeight', ChoiceType::class, [
            'label'    => 'Graisse du lien',
            'required' => false,
            'choices'  => [
                'Par défaut'    => '',
                'Léger (300)'   => '300',
                'Normal (400)'  => '400',
                'Medium (500)'  => '500',
                'Semi-gras (600)' => '600',
                'Gras (700)'    => '700',
            ],
        ])



        ->add('save', SubmitType::class , [
                'label' => 'Enregistrer',
                'attr' => [
                    'class' => 'btn btn-primary',
                ],
            ]);
    
    }

       public function getName()
    {
        return '';
    }
    
    public function getBlockPrefix()
    {
        return '';
    }


    public static function getIntro(): ?string
    {
        return 'Cette page vous permet de définir le menu principal (niveau 1) et de lier une catégorie parente.</br>
        - Sélectionnez la catégorie principale à associer à ce menu (ex. : "Homme", "Femme", etc.).</br>
        - Activez ou désactivez la visibilité du menu via le bouton dédié.</br>
        ';
    }



}