"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = SidebarCards;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _useListNavigation = require("../hooks/use-list-navigation");
var _sidebarCard = _interopRequireDefault(require("./sidebar-card"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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); }
/** A SidebarCards: list of selectable cards
 *  with optional customized header and footer
 * @uxr-only-supported
 * @midnight-gray-supported
 * @alpine-light-supported
 * */
function SidebarCards({
  ariaLabel,
  ariaLabelledBy,
  testId = 'sidebar-cards',
  items = [],
  onSelect = () => {},
  onCheckboxSelect,
  className = ''
}) {
  const ref = (0, _react.useRef)();
  const adapter = (0, _useListNavigation.useListNavigationAdapter)(navigationListMapper);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_useListNavigation.ListNavigationProvider, {
    list: items,
    container: ref,
    isDisabled: false,
    adapter: adapter,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: (0, _classnames.default)('sidebar-cards', className),
      "test-id": testId,
      role: "listbox",
      "aria-label": ariaLabel,
      "aria-labelledby": ariaLabelledBy,
      ref: ref,
      children: items.map(item => {
        const handleSelect = () => onSelect(item.id);
        const itemTestId = item.testId || `${testId}-${item.id}`;
        const isDisabled = Boolean(item.isDisabled);
        const isSelected = Boolean(item.isSelected);
        const isCheckboxDisabled = Boolean(item.isCheckboxDisabled ?? isDisabled);
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarCard.default, {
          ref: item.ref,
          id: item.id,
          leftItem: item.leftItem,
          testId: itemTestId,
          isReadOnly: false,
          title: item.title,
          titleTooltip: item.titleTooltip,
          headerContentLeft: item.headerContentLeft,
          headerContentRight: item.headerContentRight,
          content: item.content,
          isSelected: isSelected,
          isDisabled: isDisabled,
          hasCheckbox: item.hasCheckbox,
          isChecked: item.isChecked ?? isSelected,
          onCheckboxSelect: onCheckboxSelect || handleSelect,
          checkboxTooltip: item.checkboxTooltip,
          isCheckboxDisabled: isCheckboxDisabled,
          className: item.className,
          onClick: () => {
            if (!isDisabled) {
              handleSelect();
            }
          },
          shouldSelectTileOnEnter: !!onCheckboxSelect && !!onSelect
        }, item.id);
      })
    })
  });
}
function navigationListMapper(item) {
  return {
    id: item.id,
    label: item.title || item.content,
    isDisabled: !!item.isDisabled,
    isSelected: !!item.isSelected,
    isFocused: false
  };
}