import React, { useCallback } from 'react';
import classNames from 'classnames';
import SidebarCardHeader from './sidebar-card-header';
import SidebarCardContent from './sidebar-card-content';
import { useListItemNavigation, useForwardRef } from '../hooks';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/** A SidebarCards: Card
 *  with optional customized header and footer
 * @uxr-only-supported
 * @midnight-gray-supported
 * @alpine-light-supported
 * */
const SidebarCard = /*#__PURE__*/React.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
  } = useListItemNavigation({
    id,
    isSelected,
    onToggleSelected: () => {
      if (isReadOnly || isDisabled) {
        return;
      }
      if (shouldSelectTileOnEnter) {
        other.onClick();
      } else {
        onCheckboxSelect?.(id);
      }
    }
  });
  const [setForwardedRef] = useForwardRef(forwardedRef);
  const mergedRef = useCallback(el => {
    listItemRef(el);
    setForwardedRef(el);
  }, [listItemRef, setForwardedRef]);
  return (
    /*#__PURE__*/
    // useListItemNavigation returns onKeyDown, role and tabIndex
    _jsxs("div", {
      "test-id": testId,
      className: classNames('sidebar-card', className, {
        'is-selectable': !isReadOnly && !isDisabled,
        'is-disabled-card': isDisabled,
        'is-selected-card': isSelected
      }),
      ...other,
      ...listItemAttrs,
      ref: mergedRef,
      children: [leftItem, /*#__PURE__*/_jsxs("div", {
        className: "sidebar-card-content-section",
        children: [/*#__PURE__*/_jsx(SidebarCardHeader, {
          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__*/_jsx(SidebarCardContent, {
          testId: `${testId}-content`,
          content: content
        })]
      })]
    })
  );
});
export default SidebarCard;