<?php

namespace KupShop\ComponentsBundle\Twig\Extension;

use KupShop\KupShopBundle\Util\System\UrlFinder;
use Symfony\Contracts\Service\Attribute\Required;
use Twig\Extension\RuntimeExtensionInterface;

class StaticUrlRuntime implements RuntimeExtensionInterface
{
    #[Required]
    public UrlFinder $urlFinder;

    public function staticUrl(string $url, $absolute = false)
    {
        if ($absolute) {
            return $this->urlFinder->staticUrlAbsolute($url);
        }

        return $this->urlFinder->staticUrl($url);
    }

    public function encorePackage(): ?string
    {
        if ($this->urlFinder->hasCDN()) {
            return 'cdn';
        }

        return null;
    }
}
