import classNames from 'classnames';
import { define } from "../preactement/define";
import { AccordionItem } from "../../Accordion";
import { parseBooleanAttr } from "../wrapperUtils";
import { jsx as _jsx } from "preact/compat/jsx-runtime";
const attributes = ['button-class-name', 'content-class-name', 'content-id', 'default-open', 'heading', 'heading-level'];

/* eslint-disable @typescript-eslint/no-namespace */

/* eslint-enable */

function findAccordionAncestor(el) {
  let parentAccordion;
  let parentElement = el.parentElement;
  do {
    if (parentElement.tagName === 'DS-ACCORDION') {
      parentAccordion = parentElement;
      break;
    }
    parentElement = parentElement.parentElement;
  } while (parentElement != null);
  return parentAccordion;
}
const Wrapper = _ref => {
  let {
    defaultOpen,
    contentId,
    contentClassName,
    customElement,
    ...otherProps
  } = _ref;
  const parentAccordion = findAccordionAncestor(customElement);
  const bordered = parseBooleanAttr(parentAccordion?.getAttribute('bordered'));
  return /*#__PURE__*/_jsx(AccordionItem, {
    ...otherProps,
    defaultOpen: parseBooleanAttr(defaultOpen),
    id: contentId,
    contentClassName: classNames(contentClassName, bordered && 'ds-c-accordion__content--bordered')
  });
};
define('ds-accordion-item', () => Wrapper, {
  attributes,
  events: ['onChange'],
  shadow: true,
  passCustomElementProp: true
});