"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
 * Copyright 2020 The Kubernetes Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/** for html pre-rendered dom content */
class XtermDom extends _react.default.PureComponent {
  renderRow(cells) {
    if (cells.length === 1) {
      // If we have a single child with no styling, inline its text
      // directly into the row element.
      const cell = cells[0];
      if (cell.classList && cell.classList.length === 0 && cell.style && Object.keys(cell.style).length === 0) {
        const text = cell.innerText || cell.textContent || '\u00a0'; // whitespace seems to be in textContent
        return text;
      }
    }
    return cells.map((cell, idx) => {
      const text = cell.innerText || cell.textContent || '\u00a0'; // whitespace seems to be in textContent
      return cell.classList.length === 0 && !cell.style ? text : _react.default.createElement("span", {
        key: idx,
        className: cell.classList.join(' '),
        style: cell.style || {}
      }, text || '\u00a0');
    });
  }
  render() {
    return this.props.response.rows.length === 0 ? _react.default.createElement(_react.default.Fragment, null) : _react.default.createElement("div", {
      className: "kui--xterm-output padding-content scrollable scrollable-auto page-content"
    }, _react.default.createElement("div", {
      style: {
        display: 'flex',
        flex: 1
      }
    }, _react.default.createElement("div", {
      className: "xterm-container xterm-terminated"
    }, _react.default.createElement("div", {
      className: "xterm-rows"
    }, this.props.response.rows.map((_, idx) => _react.default.createElement("div", {
      key: idx
    }, this.renderRow(_)))))));
  }
}
exports.default = XtermDom;