import { toArray as _toArray } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import { createElement } from 'react-syntax-highlighter';
import { classes } from '../CodeArea.tokens.js';

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 = _toArray(children),
      firstChild = _children[0],
      restChildren = _children.slice(1);
    var hasLineNumber = isLineNumberNode(firstChild);
    var codeChildren = hasLineNumber ? restChildren : children;
    var lineClassName = hasLineNumber ? classes.line : "".concat(classes.line, " ").concat(classes.lineWithoutNumber);
    return /*#__PURE__*/React__default.createElement("span", {
      key: "code-line-".concat(rowIndex),
      className: lineClassName
    }, hasLineNumber && createElement({
      node: firstChild,
      stylesheet: stylesheet,
      useInlineStyles: useInlineStyles,
      key: "line-number-".concat(rowIndex)
    }), /*#__PURE__*/React__default.createElement("span", {
      className: classes.lineContent
    }, codeChildren.map(function (node, nodeIndex) {
      return createElement({
        node: node,
        stylesheet: stylesheet,
        useInlineStyles: useInlineStyles,
        key: "line-".concat(rowIndex, "-segment-").concat(nodeIndex)
      });
    })));
  });
};

export { renderCodeRows };
