'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var renderers = require('./renderers.js');
var renderInlineTokens = require('./renderInlineTokens.js');
var renderUtils = require('./renderUtils.js');

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

exports.renderTable = renderTable;
