<?php

use KupShop\KupShopBundle\Context\UserContext;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\KupShopBundle\Util\Contexts;
use KupShop\UserManagerBundle\Util\UserManagerUtil;

function smarty_function_is_user_manager($params, &$smarty)
{
    $userContext = Contexts::get(UserContext::class);

    $default = [
        'id' => $userContext->getActiveId(),
    ];

    $params = array_merge($default, $params);

    $userManagerUtil = ServiceContainer::getService(UserManagerUtil::class);

    $result = $userManagerUtil->isUserManager((int) $params['id']);

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
