"use strict";

exports.__esModule = true;
exports.default = void 0;
var _isEmpty2 = _interopRequireDefault(require("lodash/fp/isEmpty"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _emptySearchResult = _interopRequireDefault(require("../../atom/empty-search-result"));
var _inputSearch = _interopRequireDefault(require("../../atom/input-search"));
var _buttonLink = _interopRequireDefault(require("../../atom/button-link"));
var _chips = _interopRequireDefault(require("../../atom/chips"));
var _loader = _interopRequireDefault(require("../../atom/loader"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const buildResultView = (results, resultsAriaLabel, emptyMessages, isLoading) => {
  if (!isLoading && (0, _isEmpty2.default)(results)) {
    return /*#__PURE__*/_react.default.createElement(_emptySearchResult.default, emptyMessages);
  }
  const items = results.map((result, index) => {
    return /*#__PURE__*/_react.default.createElement("li", {
      className: _style.default.result,
      key: `result-${index}`,
      "data-name": `result-${index}`
    }, /*#__PURE__*/_react.default.createElement(_chips.default, result));
  });
  return /*#__PURE__*/_react.default.createElement("ul", {
    "aria-label": resultsAriaLabel
  }, items);
};
const SearchAndChipsResults = props => {
  const {
    search,
    selectAllButton,
    results,
    emptyMessages,
    isLoading = false,
    'results-aria-label': resultsAriaLabel
  } = props;
  const {
    onClick,
    label,
    disabled = false,
    'aria-label': ariaLabel
  } = selectAllButton;
  const resultView = buildResultView(results, resultsAriaLabel, emptyMessages, isLoading);
  const buttonProps = {
    type: 'secondary',
    label,
    'aria-label': ariaLabel,
    'data-name': `select-all-button`,
    icon: {
      position: 'right',
      type: 'add'
    },
    onClick,
    disabled
  };
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.container
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.header
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.button
  }, /*#__PURE__*/_react.default.createElement(_buttonLink.default, buttonProps)), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.search
  }, /*#__PURE__*/_react.default.createElement(_inputSearch.default, _extends({}, search, {
    theme: "coorpmanager"
  })))), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.resultContainer
  }, isLoading ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.loaderContainer
  }, /*#__PURE__*/_react.default.createElement(_loader.default, {
    className: _style.default.loader,
    theme: "coorpmanager"
  })) : resultView));
};
SearchAndChipsResults.propTypes = process.env.NODE_ENV !== "production" ? {
  selectAllButton: _propTypes.default.shape({
    label: _propTypes.default.string,
    onClick: _propTypes.default.func,
    disabled: _propTypes.default.bool,
    'aria-label': _propTypes.default.string
  }),
  isLoading: _propTypes.default.bool,
  search: _propTypes.default.shape(_inputSearch.default.PropTypes),
  results: _propTypes.default.arrayOf(_propTypes.default.shape(_chips.default.propTypes)),
  'results-aria-label': _propTypes.default.string,
  emptyMessages: _propTypes.default.shape({
    firstMessage: _propTypes.default.string,
    secondMessage: _propTypes.default.string
  })
} : {};
var _default = exports.default = SearchAndChipsResults;
//# sourceMappingURL=index.js.map