'use strict';

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

var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var reactSyntaxHighlighter = require('react-syntax-highlighter');
var CodeArea_tokens = require('../CodeArea.tokens.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var isLineNumberNode = function isLineNumberNode(node) {
  var _node$properties, _node$properties2;
  return Array.isArray(node === null || node === void 0 || (_node$properties = node.properties) === null || _node$properties === void 0 ? void 0 : _node$properties.className) && (node === null || node === void 0 || (_node$properties2 = node.properties) === null || _node$properties2 === void 0 ? void 0 : _node$properties2.className.includes('linenumber'));
};
var renderCodeRows = function renderCodeRows(_ref) {
  var rows = _ref.rows,
    stylesheet = _ref.stylesheet,
    useInlineStyles = _ref.useInlineStyles;
  return rows.map(function (row, rowIndex) {
    var children = row.children || [];
    var _children = _rollupPluginBabelHelpers.toArray(children),
      firstChild = _children[0],
      restChildren = _children.slice(1);
    var hasLineNumber = isLineNumberNode(firstChild);
    var codeChildren = hasLineNumber ? restChildren : children;
    var lineClassName = hasLineNumber ? CodeArea_tokens.classes.line : "".concat(CodeArea_tokens.classes.line, " ").concat(CodeArea_tokens.classes.lineWithoutNumber);
    return /*#__PURE__*/React__default.default.createElement("span", {
      key: "code-line-".concat(rowIndex),
      className: lineClassName
    }, hasLineNumber && reactSyntaxHighlighter.createElement({
      node: firstChild,
      stylesheet: stylesheet,
      useInlineStyles: useInlineStyles,
      key: "line-number-".concat(rowIndex)
    }), /*#__PURE__*/React__default.default.createElement("span", {
      className: CodeArea_tokens.classes.lineContent
    }, codeChildren.map(function (node, nodeIndex) {
      return reactSyntaxHighlighter.createElement({
        node: node,
        stylesheet: stylesheet,
        useInlineStyles: useInlineStyles,
        key: "line-".concat(rowIndex, "-segment-").concat(nodeIndex)
      });
    })));
  });
};

exports.renderCodeRows = renderCodeRows;
