<?php

namespace AutoAdmin\Bundle\Admin\Form\Extension;

use AutoAdmin\Bundle\Admin\Form\Type\Component\DateTimePickerType;
use AutoAdmin\Bundle\Admin\Helper\UserTimezoneProvider;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Service\Attribute\Required;

class UTCExtension extends AbstractTypeExtension
{
    protected UserTimezoneProvider $userTimezoneProvider;

    #[Required]
    public function init(UserTimezoneProvider $userTimezoneProvider): void
    {
        $this->userTimezoneProvider = $userTimezoneProvider;
    }

    public static function getExtendedTypes(): iterable
    {
        return [
            DateTimePickerType::class,
        ];
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefault('view_timezone', $this->userTimezoneProvider->getUserTimezone());

        parent::configureOptions($resolver);
    }
}
