"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = SelectedItemsBoard;
var _react = _interopRequireWildcard(require("react"));
var _faChevronDown = require("@fortawesome/free-solid-svg-icons/faChevronDown");
var _faChevronUp = require("@fortawesome/free-solid-svg-icons/faChevronUp");
var _faCircleXmark = require("@fortawesome/free-solid-svg-icons/faCircleXmark");
var _useTranslation = require("../hooks/use-translation");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _button = require("../button");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function SelectedItemsBoard({
  displayLabel,
  onItemRemove,
  onClearAll,
  listKey,
  header,
  items,
  getDefaultHeaderText,
  clearAllText,
  removeText
}) {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const [isExpanded, toggleExpanded] = (0, _react.useState)(true);
  const getSelectedItemsMessageDefault = itemsLength => itemsLength === 1 ? t('{{itemsLength}} item selected', {
    itemsLength
  }) : t('{{itemsLength}} items selected', {
    itemsLength
  });

  // not in default props because it depends on items length
  const headerContent = header || getDefaultHeaderText?.(items.length) || getSelectedItemsMessageDefault(items.length);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "selected-items-board",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("header", {
      className: "underlined",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
        onClick: () => toggleExpanded(!isExpanded),
        testId: "selected-items-board-expand-toggler",
        accentType: _button.ACCENT_TYPES.COMMAND,
        rightIcon: isExpanded ? _faChevronDown.faChevronDown : _faChevronUp.faChevronUp,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
          children: headerContent
        })
      })
    }), isExpanded && items.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
        className: "items-list",
        children: items.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
          className: "item-container",
          "test-id": "selected-items-board-item-label",
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: "item-display-label",
            "test-id": item?.testId,
            children: displayLabel(item, index)
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
            testId: "selected-items-board-remove-item-btn",
            onClick: () => onItemRemove(item, index),
            accentType: _button.ACCENT_TYPES.ROUND_ICON,
            className: "item-remove-button",
            "aria-label": removeText,
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
              icon: _faCircleXmark.faCircleXmark
            })
          })]
        }, listKey(item, index)))
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "underlined clear-all-button-wrapper",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
          testId: "selected-items-board-clear-all-btn",
          accentType: _button.ACCENT_TYPES.COMMAND,
          onClick: onClearAll,
          children: clearAllText
        })
      })]
    })]
  });
}