import { TableRenderer } from './renderers.js';
import { renderInlineTokens } from './renderInlineTokens.js';
import { renderElement, resolveTokenNode } from './renderUtils.js';

var renderTable = function renderTable(markedEngine, tokenRenderer, token, key) {
  var headerCells = token.header.map(function (cell, index) {
    return renderElement("".concat(key, "-th-").concat(index), 'th', {
      style: {
        textAlign: cell.align || undefined
      }
    }, renderInlineTokens(markedEngine, tokenRenderer, cell.tokens, "".concat(key, "-th-").concat(index, "-content")));
  });
  var bodyRows = token.rows.map(function (row, rowIndex) {
    return renderElement("".concat(key, "-tr-").concat(rowIndex), 'tr', undefined, row.map(function (cell, cellIndex) {
      return renderElement("".concat(key, "-td-").concat(rowIndex, "-").concat(cellIndex), 'td', {
        style: {
          textAlign: cell.align || undefined
        }
      }, renderInlineTokens(markedEngine, tokenRenderer, cell.tokens, "".concat(key, "-td-").concat(rowIndex, "-").concat(cellIndex, "-content")));
    }));
  });
  var children = [renderElement("".concat(key, "-thead"), 'thead', undefined, renderElement("".concat(key, "-thead-row"), 'tr', undefined, headerCells)), renderElement("".concat(key, "-tbody"), 'tbody', undefined, bodyRows)];
  var defaultNode = renderElement(key, TableRenderer, undefined, children);
  return resolveTokenNode(tokenRenderer, token, defaultNode, children);
};

export { renderTable };
