<?js
    var params = obj;
    
    /* sort subparams under their parent params (like opts.classname) */
    var parentParam = null;
    params.forEach(function(param, i) {
        if (!param) { return; }
        if ( parentParam && param.name && param.name.indexOf(parentParam.name + '.') === 0 ) {
            param.name = param.name.substr(parentParam.name.length+1);
            parentParam.subparams = parentParam.subparams || [];
            parentParam.subparams.push(param);
            params[i] = null;
        }
        else {
            parentParam = param;
        }
    });
    
    /* determine if we need extra columns, "attributes" and "default" */
    params.hasAttributes = false;
    params.hasDefault = false;
    params.hasName = false;
    
    var colspan = 2;
    params.forEach(function(param) {
        if (!param) { return; }
        if (param.type && param.type.names && param.type.names.indexOf('undefined') !== -1) {
            param.optional = true;
        }
        if (param.name.indexOf('var_') == 0) {
            params.hasAttributes = true;
            param.variable = true;
        }
        
        if (param.optional || param.nullable) {
            params.hasAttributes = true;
        }
        
        if (param.name) {
            params.hasName = true;
        }
        
        if (typeof param.defaultvalue !== 'undefined') {
            ++colspan;
            params.hasDefault = true;
        }
    });
?>

<table class="params">
    <thead>
	<tr>
		<?js if (params.hasName) {?>
		<th>Name</th>
		<?js } ?>
		
		<th>Type</th>
		
		<?js if (params.hasDefault) {?>
		<th>Default</th>
		<?js } ?>
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	<?js
        var self = this;
	    params.forEach(function(param) {
	        if (!param) { return; }
	?>
	
        <tr class="<?js= (param.stability && param.stability !== 'stable') ? 'unstable' : '' ?>">
            <?js if (params.hasName) {?>
                <td class="name"><code><?js= param.name.replace(/^opt_/, "") ?></code></td>
            <?js } ?>
            
            <?js if (!param.subparams) {?>
            <td class="type">
            <?js if (param.type && param.type.names) {?>
                <?js= self.partial('type.tmpl', param.type.names) ?>
            <?js } ?>
            </td>
            
            <?js if (params.hasDefault) {?>
                <td class="default">
                <?js if (typeof param.defaultvalue !== 'undefined') { ?>
                    <?js= self.htmlsafe(param.defaultvalue) ?>
                <?js } ?>
                </td>
            <?js } ?>
            <?js } ?>
            
            <td<?js= (param.subparams ? ' colspan=' + colspan : ' ') ?> class="description last">
                <?js if (param.stability) { ?>
                    <?js= self.partial('stability.tmpl', param) ?>
                <?js } ?>
                <?js= param.description ?><?js if (param.subparams) { ?>
                <?js= self.partial('params.tmpl', param.subparams) ?>
            <?js } ?></td>
        </tr>
	
	<?js }); ?>
	</tbody>
</table>