"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ActiveFiltersList = ActiveFiltersList;
var _react = _interopRequireDefault(require("react"));
var _uniqueId = _interopRequireDefault(require("lodash-es/uniqueId"));
var _faFilter = require("@fortawesome/free-solid-svg-icons/faFilter");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _button = require("../button");
var _filterItem = _interopRequireDefault(require("./filter-item"));
var _useTranslation = require("../hooks/use-translation");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/** Component for listing all currently enabled filters */
function ActiveFiltersList({
  filters,
  onClearAll,
  showIcon = true,
  onClearOne,
  testId = '',
  filterByText,
  clearAllText,
  deleteFilterItemText
}) {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  if (!filters || !filters.length) {
    return null;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "active-filters-list",
    "test-id": testId,
    children: [showIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
      icon: _faFilter.faFilter,
      "aria-label": filterByText ?? t('Filter By'),
      "aria-hidden": "false"
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "filters-container",
      role: "list",
      children: filters.map(filter => /*#__PURE__*/(0, _jsxRuntime.jsx)(_filterItem.default, {
        id: filter.key || (0, _uniqueId.default)(),
        filter: filter,
        onClearOne: onClearOne,
        deleteFilterItemText: deleteFilterItemText ?? t('Delete filter item')
      }, filter.key || (0, _uniqueId.default)()))
    }), onClearAll ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
      onClick: onClearAll,
      className: "filters-clear button command",
      "test-id": "active-filter-list-clear-all",
      type: _button.BUTTON_TYPES.BUTTON,
      children: clearAllText ?? t('Clear all')
    }) : null]
  });
}