"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _sidebarCardHeader = _interopRequireDefault(require("./sidebar-card-header"));
var _sidebarCardContent = _interopRequireDefault(require("./sidebar-card-content"));
var _hooks = require("../hooks");
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: Card
 *  with optional customized header and footer
 * @uxr-only-supported
 * @midnight-gray-supported
 * @alpine-light-supported
 * */
const SidebarCard = /*#__PURE__*/_react.default.forwardRef(function SidebarCard({
  testId = 'sidebar-card',
  id,
  isDisabled = false,
  isSelected = false,
  isReadOnly = false,
  hasCheckbox = false,
  isChecked = false,
  leftItem = null,
  checkboxTooltip = '',
  isCheckboxDisabled,
  title,
  titleTooltip,
  headerContentLeft,
  headerContentRight,
  content,
  onCheckboxSelect,
  className = '',
  shouldSelectTileOnEnter,
  ...other
}, forwardedRef) {
  const {
    listItemAttrs,
    ref: listItemRef
  } = (0, _hooks.useListItemNavigation)({
    id,
    isSelected,
    onToggleSelected: () => {
      if (isReadOnly || isDisabled) {
        return;
      }
      if (shouldSelectTileOnEnter) {
        other.onClick();
      } else {
        onCheckboxSelect?.(id);
      }
    }
  });
  const [setForwardedRef] = (0, _hooks.useForwardRef)(forwardedRef);
  const mergedRef = (0, _react.useCallback)(el => {
    listItemRef(el);
    setForwardedRef(el);
  }, [listItemRef, setForwardedRef]);
  return (
    /*#__PURE__*/
    // useListItemNavigation returns onKeyDown, role and tabIndex
    (0, _jsxRuntime.jsxs)("div", {
      "test-id": testId,
      className: (0, _classnames.default)('sidebar-card', className, {
        'is-selectable': !isReadOnly && !isDisabled,
        'is-disabled-card': isDisabled,
        'is-selected-card': isSelected
      }),
      ...other,
      ...listItemAttrs,
      ref: mergedRef,
      children: [leftItem, /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: "sidebar-card-content-section",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarCardHeader.default, {
          testId: `${testId}-header`,
          id: id,
          title: title,
          titleTooltip: titleTooltip,
          headerContentLeft: headerContentLeft,
          headerContentRight: headerContentRight,
          hasCheckbox: hasCheckbox,
          checkboxTooltip: checkboxTooltip,
          isChecked: isChecked,
          isCheckboxDisabled: isCheckboxDisabled ?? isDisabled,
          onCheckboxSelect: onCheckboxSelect,
          checkboxTabIndex: listItemAttrs.tabIndex
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarCardContent.default, {
          testId: `${testId}-content`,
          content: content
        })]
      })]
    })
  );
});
var _default = exports.default = SidebarCard;