"use strict";

exports.__esModule = true;
exports.default = void 0;
var _toString2 = _interopRequireDefault(require("lodash/fp/toString"));
var _size2 = _interopRequireDefault(require("lodash/fp/size"));
var _pipe2 = _interopRequireDefault(require("lodash/fp/pipe"));
var _map2 = _interopRequireDefault(require("lodash/fp/map"));
var _filter2 = _interopRequireDefault(require("lodash/fp/filter"));
var _react = _interopRequireDefault(require("react"));
var _chip = _interopRequireDefault(require("../../atom/chip"));
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 }; }
const FilterChip = (props, context) => {
  const {
    options,
    title,
    onClear
  } = props;
  const selectedFiltersCount = (0, _pipe2.default)((0, _filter2.default)({
    selected: true
  }), _size2.default)(options);
  const hasSelectedFilters = selectedFiltersCount > 0;
  const translate = (0, _provider.GetTranslateFromContext)(context);
  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
  }), hasSelectedFilters ? /*#__PURE__*/_react.default.createElement(_tag.default, {
    label: (0, _toString2.default)(selectedFiltersCount),
    type: "info",
    size: "S"
  }) : null), hasSelectedFilters ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.buttonContainer
  }, /*#__PURE__*/_react.default.createElement(_buttonLink.default, {
    customStyle: {
      fontWeight: 'normal',
      padding: 0
    },
    label: translate('clear'),
    type: "text",
    "data-name": "filter-chip-clear-button",
    "aria-label": "filter chip clear button",
    onClick: onClear
  })) : null), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.optionsContainer
  }, (0, _map2.default)(({
    icon,
    label,
    onClick,
    type,
    selected
  }) => {
    function handleClick() {
      onClick(type);
    }
    return /*#__PURE__*/_react.default.createElement(_chip.default, {
      leftIcon: icon,
      text: label,
      key: label,
      selected: selected,
      onClick: handleClick
    });
  }, options)));
};
FilterChip.propTypes = process.env.NODE_ENV !== "production" ? _propTypes.default : {};
FilterChip.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
var _default = exports.default = FilterChip;
//# sourceMappingURL=index.js.map