"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _ramda = require("ramda");

var _classnames = _interopRequireDefault(require("classnames"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _ErrorBoundary = require("../ErrorBoundary");

var _Spinner = _interopRequireDefault(require("../Spinner"));

require("./style.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var ListView = function ListView(_ref) {
  var data = _ref.data,
      renderContent = _ref.renderContent,
      onClick = _ref.onClick,
      renderHeader = _ref.renderHeader,
      renderFooter = _ref.renderFooter,
      isLoading = _ref.isLoading;
  var isClickable = !(0, _ramda.isNil)(onClick);

  var header = renderHeader && _react.default.createElement("div", {
    className: "vs-list-view-header"
  }, renderHeader());

  var spinner = _react.default.createElement("div", {
    className: "vs-list-view-spinner-wrapper"
  }, _react.default.createElement(_Spinner.default, {
    size: "extra-large"
  }));

  var listViewContent = _react.default.createElement("div", {
    className: "vs-list-view"
  }, (0, _ramda.defaultTo)([])(data).map(function (item, index) {
    return _react.default.createElement("div", {
      key: item.id || index,
      className: (0, _classnames.default)({
        'vs-list-item': true,
        'vs-list-item-clickable': isClickable
      }),
      onClick: isClickable ? function () {
        return onClick(item);
      } : undefined
    }, renderContent(item));
  }));

  var footer = renderFooter && _react.default.createElement("div", {
    className: "vs-list-view-footer"
  }, renderFooter());

  return _react.default.createElement("div", {
    className: "vs-list-view-container"
  }, header, isLoading && spinner, !isLoading && listViewContent, footer);
};

ListView.propTypes = {
  data: _propTypes.default.array,
  renderContent: _propTypes.default.func.isRequired,
  onClick: _propTypes.default.func,
  renderHeader: _propTypes.default.func,
  renderFooter: _propTypes.default.func,
  isLoading: _propTypes.default.bool.isRequired
};
ListView.defaultProps = {
  isLoading: false
};

var _default = (0, _ErrorBoundary.withErrorBoundary)(ListView);

exports.default = _default;