"use strict";

exports.__esModule = true;
exports.default = void 0;
var _kebabCase2 = _interopRequireDefault(require("lodash/fp/kebabCase"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
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 _selectMultiple = _interopRequireDefault(require("../../molecule/select-multiple"));
var _card = _interopRequireDefault(require("../../molecule/card"));
var _inputSwitch = _interopRequireDefault(require("../../atom/input-switch"));
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 = (courses, coursesSelectionAriaLabel, emptyMessages, isLoading) => {
  if (!isLoading && (0, _isEmpty2.default)(courses)) {
    return /*#__PURE__*/_react.default.createElement(_emptySearchResult.default, emptyMessages);
  }
  const items = courses.map((card, index) => {
    const title = (0, _get2.default)('title', card);
    const type = (0, _get2.default)('type', card);
    return /*#__PURE__*/_react.default.createElement("li", {
      className: _style.default.cards,
      key: `card-${index}`,
      "data-name": `${type}-${(0, _kebabCase2.default)(title)}`
    }, /*#__PURE__*/_react.default.createElement(_card.default, card));
  });
  return /*#__PURE__*/_react.default.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.default.createElement("div", {
    className: _style.default.container
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.filters
  }, /*#__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.contentFilter
  }, /*#__PURE__*/_react.default.createElement(_selectMultiple.default, contentTypeFilter)), /*#__PURE__*/_react.default.createElement(_inputSwitch.default, switchButton)), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.cardsContainer,
    "data-name": 'courses-result'
  }, isLoading ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.loaderContainer
  }, /*#__PURE__*/_react.default.createElement(_loader.default, {
    className: _style.default.loader,
    theme: "coorpmanager"
  })) : resultView));
};
CourseSelection.propTypes = process.env.NODE_ENV !== "production" ? {
  search: _propTypes.default.shape(_inputSearch.default.PropTypes),
  isLoading: _propTypes.default.bool,
  contentTypeFilter: _propTypes.default.shape(_selectMultiple.default.PropTypes),
  courses: _propTypes.default.arrayOf(_propTypes.default.shape(_card.default.propTypes)),
  'courses-selection-aria-label': _propTypes.default.string,
  emptyMessages: _propTypes.default.shape({
    firstMessage: _propTypes.default.string,
    secondMessage: _propTypes.default.string
  }),
  switchButton: _propTypes.default.shape(_inputSwitch.default.PropTypes)
} : {};
var _default = exports.default = CourseSelection;
//# sourceMappingURL=index.js.map