import classNames from 'classnames';
import { jsx as _jsx } from "react/jsx-runtime";
const handleKeyDown = e => {
  const target = e.target;
  const accordionElement = e.currentTarget;
  if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
    const triggers = Array.prototype.slice.call(accordionElement.querySelectorAll('.ds-c-accordion__button'));
    const direction = e.key === 'ArrowDown' ? 1 : -1;
    const index = triggers.indexOf(target);
    const length = triggers.length;
    const newIndex = (index + length + direction) % length;
    triggers[newIndex].focus();
    e.preventDefault();
  }
};

/**
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/accordion/).
 */
export const Accordion = _ref => {
  let {
    bordered,
    children,
    className
  } = _ref;
  const classes = classNames('ds-c-accordion', bordered && 'ds-c-accordion--bordered', className);
  return /*#__PURE__*/_jsx("div", {
    onKeyDown: handleKeyDown,
    className: classes,
    children: children
  });
};
export default Accordion;