import _kebabCase from "lodash/fp/kebabCase";
import _get from "lodash/fp/get";
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 SelectMultiple from '../../molecule/select-multiple';
import Card from '../../molecule/card';
import InputSwitch from '../../atom/input-switch';
import Loader from '../../atom/loader';
import style from './style.css';
const buildResultView = (courses, coursesSelectionAriaLabel, emptyMessages, isLoading) => {
  if (!isLoading && _isEmpty(courses)) {
    return /*#__PURE__*/React.createElement(EmptySearchResult, emptyMessages);
  }
  const items = courses.map((card, index) => {
    const title = _get('title', card);
    const type = _get('type', card);
    return /*#__PURE__*/React.createElement("li", {
      className: style.cards,
      key: `card-${index}`,
      "data-name": `${type}-${_kebabCase(title)}`
    }, /*#__PURE__*/React.createElement(Card, card));
  });
  return /*#__PURE__*/React.createElement("ul", {
    "aria-label": coursesSelectionAriaLabel
  }, items);
};
const CourseSelection = props => {
  const {
    search,
    contentTypeFilter,
    courses,
    emptyMessages,
    isLoading = false,
    'courses-selection-aria-label': coursesSelectionAriaLabel,
    switchButton
  } = props;
  const resultView = buildResultView(courses, coursesSelectionAriaLabel, emptyMessages, isLoading);
  return /*#__PURE__*/React.createElement("div", {
    className: style.container
  }, /*#__PURE__*/React.createElement("div", {
    className: style.filters
  }, /*#__PURE__*/React.createElement("div", {
    className: style.search
  }, /*#__PURE__*/React.createElement(Search, _extends({}, search, {
    theme: "coorpmanager"
  }))), /*#__PURE__*/React.createElement("div", {
    className: style.contentFilter
  }, /*#__PURE__*/React.createElement(SelectMultiple, contentTypeFilter)), /*#__PURE__*/React.createElement(InputSwitch, switchButton)), /*#__PURE__*/React.createElement("div", {
    className: style.cardsContainer,
    "data-name": 'courses-result'
  }, isLoading ? /*#__PURE__*/React.createElement("div", {
    className: style.loaderContainer
  }, /*#__PURE__*/React.createElement(Loader, {
    className: style.loader,
    theme: "coorpmanager"
  })) : resultView));
};
CourseSelection.propTypes = process.env.NODE_ENV !== "production" ? {
  search: PropTypes.shape(Search.PropTypes),
  isLoading: PropTypes.bool,
  contentTypeFilter: PropTypes.shape(SelectMultiple.PropTypes),
  courses: PropTypes.arrayOf(PropTypes.shape(Card.propTypes)),
  'courses-selection-aria-label': PropTypes.string,
  emptyMessages: PropTypes.shape({
    firstMessage: PropTypes.string,
    secondMessage: PropTypes.string
  }),
  switchButton: PropTypes.shape(InputSwitch.PropTypes)
} : {};
export default CourseSelection;
//# sourceMappingURL=index.js.map