<?php

namespace AutoAdmin\Bundle\Admin\Twig\Extension;

use AutoAdmin\Bundle\Content\Context\ContentContext;
use AutoAdmin\Bundle\Content\Site\SiteContextHelper;
use AutoAdmin\Bundle\Content\Translation\LocaleSwitchHelper;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class LocaleExtension extends AbstractExtension
{
    public function __construct(
        protected SiteContextHelper $contextHelper,
        protected LocaleSwitchHelper $localeSwitchHelper,
        protected ContentContext $contentContext,
    ) {
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('aa_admin_locale_switches', [$this, 'getSwitches']),
        ];
    }

    public function getSwitches(?object $content = null): array
    {
        $localeSwitch = $this->localeSwitchHelper->buildCurrentSwitch($content);
        $localeSwitchers = $this->localeSwitchHelper->buildAlternateSwitches($content);

        return [
            'locale_current_switch' => $localeSwitch,
            'locale_alternate_switches' => $localeSwitchers,
        ];
    }
}
