"use strict";

exports.__esModule = true;
exports.default = void 0;
var _toString2 = _interopRequireDefault(require("lodash/fp/toString"));
var _flatMap2 = _interopRequireDefault(require("lodash/fp/flatMap"));
var _filter2 = _interopRequireDefault(require("lodash/fp/filter"));
var _pipe2 = _interopRequireDefault(require("lodash/fp/pipe"));
var _size2 = _interopRequireDefault(require("lodash/fp/size"));
var _map2 = _interopRequireDefault(require("lodash/fp/map"));
var _react = _interopRequireDefault(require("react"));
var _filterChip = _interopRequireDefault(require("../../organism/filter-chip"));
var _filterCheckboxAndSearch = _interopRequireDefault(require("../../organism/filter-checkbox-and-search"));
var _title = _interopRequireDefault(require("../../atom/title"));
var _tag = _interopRequireDefault(require("../../atom/tag"));
var _buttonLink = _interopRequireDefault(require("../../atom/button-link"));
var _provider = _interopRequireWildcard(require("../../atom/provider"));
var _propTypes = _interopRequireDefault(require("./prop-types"));
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// @ts-expect-error convert is not recognized by the types
const uncappedMap = _map2.default.convert({
  cap: false
});
const CLEAR_ALL_BUTTON_STYLE = {
  fontWeight: 'normal',
  padding: 0
};
const FilterSeparator = /*#__PURE__*/_react.default.createElement("div", {
  className: _style.default.filterSeparator
});
const buildFilters = filterOptions => {
  const {
    type,
    options
  } = filterOptions;
  switch (type) {
    case 'chip':
      return /*#__PURE__*/_react.default.createElement(_filterChip.default, options);
    case 'checkbox':
      return /*#__PURE__*/_react.default.createElement(_filterCheckboxAndSearch.default, options);
    default:
      return null;
  }
};
const MultiFilterPanel = (props, context) => {
  const {
    title,
    onClearAll,
    options
  } = props;
  const translate = (0, _provider.GetTranslateFromContext)(context);
  const allSelectedFilters = (0, _pipe2.default)((0, _map2.default)('options'), (0, _flatMap2.default)('options'), (0, _filter2.default)({
    selected: true
  }), _size2.default)(options);
  const hasSelectedFilters = allSelectedFilters > 0;
  const filters = uncappedMap((filterOptions, i) => {
    const isLastItem = i + 1 === (0, _size2.default)(options);
    return /*#__PURE__*/_react.default.createElement("div", {
      key: i
    }, buildFilters(filterOptions), isLastItem ? null : FilterSeparator);
  }, options);
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.header
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.titleContainer
  }, /*#__PURE__*/_react.default.createElement(_title.default, {
    title: title,
    type: "form-group",
    titleSize: "standard-light-weight"
  }), hasSelectedFilters ? /*#__PURE__*/_react.default.createElement(_tag.default, {
    label: (0, _toString2.default)(allSelectedFilters),
    type: "info",
    size: "S"
  }) : null), hasSelectedFilters ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.buttonContainer
  }, /*#__PURE__*/_react.default.createElement(_buttonLink.default, {
    customStyle: CLEAR_ALL_BUTTON_STYLE,
    label: translate('clear_all'),
    type: "text",
    "data-name": "filters-all-clear-button",
    "aria-label": "filters all clear button",
    onClick: onClearAll
  })) : null), filters);
};
MultiFilterPanel.propTypes = process.env.NODE_ENV !== "production" ? _propTypes.default : {};
MultiFilterPanel.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
var _default = exports.default = MultiFilterPanel;
//# sourceMappingURL=index.js.map