"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "renderTable", {
    enumerable: true,
    get: function() {
        return renderTable;
    }
});
const _renderers = require("./renderers");
const _renderInlineTokens = require("./renderInlineTokens");
const _renderUtils = require("./renderUtils");
const renderTable = (markedEngine, tokenRenderer, token, key)=>{
    const headerCells = token.header.map((cell, index)=>(0, _renderUtils.renderElement)(`${key}-th-${index}`, 'th', {
            style: {
                textAlign: cell.align || undefined
            }
        }, (0, _renderInlineTokens.renderInlineTokens)(markedEngine, tokenRenderer, cell.tokens, `${key}-th-${index}-content`)));
    const bodyRows = token.rows.map((row, rowIndex)=>(0, _renderUtils.renderElement)(`${key}-tr-${rowIndex}`, 'tr', undefined, row.map((cell, cellIndex)=>(0, _renderUtils.renderElement)(`${key}-td-${rowIndex}-${cellIndex}`, 'td', {
                style: {
                    textAlign: cell.align || undefined
                }
            }, (0, _renderInlineTokens.renderInlineTokens)(markedEngine, tokenRenderer, cell.tokens, `${key}-td-${rowIndex}-${cellIndex}-content`)))));
    const children = [
        (0, _renderUtils.renderElement)(`${key}-thead`, 'thead', undefined, (0, _renderUtils.renderElement)(`${key}-thead-row`, 'tr', undefined, headerCells)),
        (0, _renderUtils.renderElement)(`${key}-tbody`, 'tbody', undefined, bodyRows)
    ];
    const defaultNode = (0, _renderUtils.renderElement)(key, _renderers.TableRenderer, undefined, children);
    return (0, _renderUtils.resolveTokenNode)(tokenRenderer, token, defaultNode, children);
};
