import React, { useRef } from 'react';
import classNames from 'classnames';
import { useListNavigationAdapter, ListNavigationProvider } from '../hooks/use-list-navigation';
import SidebarCard from './sidebar-card';
import { jsx as _jsx } from "react/jsx-runtime";
/** A SidebarCards: list of selectable cards
 *  with optional customized header and footer
 * @uxr-only-supported
 * @midnight-gray-supported
 * @alpine-light-supported
 * */
export default function SidebarCards({
  ariaLabel,
  ariaLabelledBy,
  testId = 'sidebar-cards',
  items = [],
  onSelect = () => {},
  onCheckboxSelect,
  className = ''
}) {
  const ref = useRef();
  const adapter = useListNavigationAdapter(navigationListMapper);
  return /*#__PURE__*/_jsx(ListNavigationProvider, {
    list: items,
    container: ref,
    isDisabled: false,
    adapter: adapter,
    children: /*#__PURE__*/_jsx("div", {
      className: classNames('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__*/_jsx(SidebarCard, {
          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
  };
}