"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ACTION_BAR_TRAY_ITEM_PLACEMENT = void 0;
exports.ActionBar = ActionBar;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _actionBarSection = require("./action-bar-section");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ACTION_BAR_TRAY_ITEM_PLACEMENT = exports.ACTION_BAR_TRAY_ITEM_PLACEMENT = {
  LEFT: 'left',
  RIGHT: 'right'
};
/** ActionBar displays grouped lists of actions
 * [CAPITALIZATION] Use sentence case for items, unless referencing a proper noun (named tab, for example).
 * @midnight-gray-supported
 * @alpine-light-supported
 */
function ActionBar({
  actionItemsList,
  isTray = false,
  className,
  testId
}) {
  const actionItemMap = actionItemsList.reduce((map, actionItem) => {
    const formattedActionItem = /*#__PURE__*/_react.default.isValidElement(actionItem) ? {
      element: actionItem
    } : actionItem;
    try {
      map.get(formattedActionItem.placement || ACTION_BAR_TRAY_ITEM_PLACEMENT.LEFT)?.push(formattedActionItem);
    } catch (error) {
      throw Error(`Action item with incorrect placement detected in ActionBar: ${error}`);
    }
    return map;
  }, new Map([[ACTION_BAR_TRAY_ITEM_PLACEMENT.LEFT, []], [ACTION_BAR_TRAY_ITEM_PLACEMENT.RIGHT, []]]));
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: (0, _classnames.default)(className, 'action-bar-component', {
      tray: isTray
    }),
    "test-id": testId,
    children: actionItemMap && Array.from(actionItemMap, ([key, actionsList]) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_actionBarSection.ActionBarSection, {
      position: key,
      actionsList: actionsList
    }, key))
  });
}