import _isEmpty from "lodash/fp/isEmpty";
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); }
import React from 'react';
import PropTypes from 'prop-types';
import EmptySearchResult from '../../atom/empty-search-result';
import Search from '../../atom/input-search';
import ButtonLink from '../../atom/button-link';
import Chips from '../../atom/chips';
import Loader from '../../atom/loader';
import style from './style.css';
const buildResultView = (results, resultsAriaLabel, emptyMessages, isLoading) => {
  if (!isLoading && _isEmpty(results)) {
    return /*#__PURE__*/React.createElement(EmptySearchResult, emptyMessages);
  }
  const items = results.map((result, index) => {
    return /*#__PURE__*/React.createElement("li", {
      className: style.result,
      key: `result-${index}`,
      "data-name": `result-${index}`
    }, /*#__PURE__*/React.createElement(Chips, result));
  });
  return /*#__PURE__*/React.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.createElement("div", {
    className: style.container
  }, /*#__PURE__*/React.createElement("div", {
    className: style.header
  }, /*#__PURE__*/React.createElement("div", {
    className: style.button
  }, /*#__PURE__*/React.createElement(ButtonLink, buttonProps)), /*#__PURE__*/React.createElement("div", {
    className: style.search
  }, /*#__PURE__*/React.createElement(Search, _extends({}, search, {
    theme: "coorpmanager"
  })))), /*#__PURE__*/React.createElement("div", {
    className: style.resultContainer
  }, isLoading ? /*#__PURE__*/React.createElement("div", {
    className: style.loaderContainer
  }, /*#__PURE__*/React.createElement(Loader, {
    className: style.loader,
    theme: "coorpmanager"
  })) : resultView));
};
SearchAndChipsResults.propTypes = process.env.NODE_ENV !== "production" ? {
  selectAllButton: PropTypes.shape({
    label: PropTypes.string,
    onClick: PropTypes.func,
    disabled: PropTypes.bool,
    'aria-label': PropTypes.string
  }),
  isLoading: PropTypes.bool,
  search: PropTypes.shape(Search.PropTypes),
  results: PropTypes.arrayOf(PropTypes.shape(Chips.propTypes)),
  'results-aria-label': PropTypes.string,
  emptyMessages: PropTypes.shape({
    firstMessage: PropTypes.string,
    secondMessage: PropTypes.string
  })
} : {};
export default SearchAndChipsResults;
//# sourceMappingURL=index.js.map