"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = renderBody;
var _i18n = require("@kui-shell/core/mdist/api/i18n");
var _react = _interopRequireDefault(require("react"));
var _Title = require("@patternfly/react-core/dist/esm/components/Title");
var _Bullseye = require("@patternfly/react-core/dist/esm/layouts/Bullseye");
var _TableComposable = require("@patternfly/react-table/dist/esm/components/TableComposable");
var _EmptyState = require("@patternfly/react-core/dist/esm/components/EmptyState");
var _searchIcon = _interopRequireDefault(require("@patternfly/react-icons/dist/esm/icons/search-icon"));
var _TableCell = _interopRequireDefault(require("./TableCell"));
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.
 */

const strings = (0, _i18n.i18n)('plugin-client-common');
/**
 * Render the TableBody part
 *
 * @param offset offset into the kuiTable.body model
 *
 */
function renderBody(kuiTable, justUpdated,
// rowKey index
tab, repl, offset) {
  const emptyState = () => {
    return _react.default.createElement(_TableComposable.Tr, null, _react.default.createElement(_TableComposable.Td, {
      "data-is-empty": true,
      colSpan: kuiTable.header ? kuiTable.header.attributes.length + 1 : 0
    }, _react.default.createElement(_Bullseye.Bullseye, null, _react.default.createElement(_EmptyState.EmptyState, {
      variant: _EmptyState.EmptyStateVariant.small
    }, _react.default.createElement(_EmptyState.EmptyStateIcon, {
      icon: _searchIcon.default
    }), _react.default.createElement(_Title.Title, {
      headingLevel: "h2",
      size: "lg"
    }, strings('No results found'))))));
  };
  return _react.default.createElement(_TableComposable.Tbody, null, kuiTable.body.length === 0 ? emptyState() : kuiTable.body.map((kuiRow, ridx) => {
    const updated = justUpdated[kuiRow.rowKey || kuiRow.name];
    const cell = (0, _TableCell.default)(kuiTable, kuiRow, updated, tab, repl);
    const key = kuiRow.key || (kuiTable.header ? kuiTable.header.key || kuiTable.header.name : undefined);
    return _react.default.createElement(_TableComposable.Tr, {
      key: ridx,
      "data-row-key": kuiRow.rowKey,
      "data-name": kuiTable.body[offset + ridx].name
    }, cell(key, kuiRow.name, undefined, kuiRow.outerCSS, kuiRow.css, kuiRow.onclick, 0), kuiRow.attributes && kuiRow.attributes.map((attr, idx) => cell(attr.key, attr.value, attr.tag, attr.outerCSS, attr.css, attr.onclick, idx + 1)));
  }));
}