<?php

use KupShop\KupShopBundle\Context\LanguageContext;
use KupShop\KupShopBundle\Util\Contexts;

function smarty_function_is_znz_store_visible($params, &$smarty)
{
    if (empty($params['store'])) {
        throw new InvalidArgumentException('Missing "store" parameter');
    }

    $result = ($params['store']['figure'] ?? 'N') === 'Y';

    $data = $params['store']['data'] ?? [];
    if (!empty($data['languages'])) {
        $languageId = Contexts::get(LanguageContext::class)->getActiveId();
        if (!in_array($languageId, $data['languages'])) {
            $result = false;
        }
    }

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