<?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 Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;

final class LocalBusinessOpeningHoursType extends AbstractType
{
    private const DAYS = [
        'Lundi' => 'Monday',
        'Mardi' => 'Tuesday',
        'Mercredi' => 'Wednesday',
        'Jeudi' => 'Thursday',
        'Vendredi' => 'Friday',
        'Samedi' => 'Saturday',
        'Dimanche' => 'Sunday',
    ];

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('dayOfWeek', ChoiceType::class, [
                'label' => 'Jours concernés',
                'choices' => self::DAYS,
                'multiple' => true,
                'expanded' => true,
                'constraints' => [
                    new Assert\Count(min: 1, minMessage: 'Sélectionnez au moins un jour.'),
                ],
            ])
            ->add('opens', TimeType::class, [
                'label' => 'Ouverture',
                'widget' => 'single_text',
                'input' => 'string',
                'input_format' => 'H:i',
                'with_seconds' => false,
            ])
            ->add('closes', TimeType::class, [
                'label' => 'Fermeture',
                'widget' => 'single_text',
                'input' => 'string',
                'input_format' => 'H:i',
                'with_seconds' => false,
            ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => null,
            'empty_data' => [
                'dayOfWeek' => [],
                'opens' => '',
                'closes' => '',
            ],
        ]);
    }

    public function getBlockPrefix(): string
    {
        return 'local_business_opening_hours';
    }
}
