<?php

use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\KupShopBundle\Util\System\UrlFinder;

function smarty_function_get_typekit_url($params, &$smarty)
{
    if (empty($params['id'])) {
        throw new InvalidArgumentException('Missing required argument \'id\'');
    }

    /** @var UrlFinder $urlFinder */
    $urlFinder = ServiceContainer::getService(UrlFinder::class);

    if ($urlFinder->hasCDN()) {
        return $urlFinder->staticUrlAbsolute("/_cdn/typekit/{$params['id']}");
    }

    return "https://use.typekit.net/{$params['id']}.css";
}
