<?php

function smarty_function_insert_autocomplete_form($params, $smarty)
{
    static $instance = 0;

    $defaults = [
        'instance' => $instance,
    ];

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

    $requiredParams = ['type', 'searchInput', 'inputName', 'items'];
    foreach ($requiredParams as $requiredParam) {
        if (!array_key_exists($requiredParam, $params)) {
            throw new InvalidArgumentException(
                sprintf('Missing required parameter "%s"', $requiredParam)
            );
        }
    }

    echo $smarty->_subTemplateRender('autocomplete-form/'.$params['type'].'.tpl', $smarty->cache_id, $smarty->compile_id, 0, null, $params, 0, false);

    $instance++;
}
