<?js
    var params = obj;

    /* sort subparams under their parent params (like opts.classname) */
    var parentParam = null;
    params.forEach(function(param, i) {
        var paramRegExp;

        if (!param) {
            return;
        }

        if (parentParam && parentParam.name && param.name) {
            paramRegExp = new RegExp('^(?:' + parentParam.name + '(?:\\[\\])*)\\.(.+)$');

            if ( paramRegExp.test(param.name) ) {
                param.name = RegExp.$1;
                parentParam.subparams = parentParam.subparams || [];
                parentParam.subparams.push(param);
                params[i] = null;
            }
            else {
                parentParam = param;
            }
        }
        else {
            parentParam = param;
        }
    });

?>

<table class="params">
    <thead>
    <tr>
        <th>Name</th>
        <th>Type</th>
        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    <?js
        var self = this;
         const displayParam = (param,indent=0) => {
            if (!param) { return; }
    ?>

        <tr>
            <td class="name">
                <code>
                   <?js for( var k = 0; k < indent; k++) { ?>
                          &nbsp;
                   <?js } ?>
                   <?js= (indent ? '.' : '') + param.name + (param.variable ? '...' : '') ?>
                </code>
            </td>
            <td class="type">
            <?js if (param.type && param.type.names) {?>
                <?js= self.partial('type.tmpl', param.type.names) ?>
                <?js if (param.optional) { ?>
                    (opt.)
                <?js } ?>
            <?js } ?>
            </td>
            <td class="description last">
               <?js= param.description ?>
            </td>
        </tr>
        <?js if (param.subparams) param.subparams.forEach((p) => displayParam(p,indent+1)); ?>
    <?js
         };
         params.forEach( (p) => displayParam(p) );
     ?>
    </tbody>
</table>
