"use strict";

var _classnames = _interopRequireDefault(require("classnames"));
var _define = require("../preactement/define");
var _Accordion = require("../../Accordion");
var _wrapperUtils = require("../wrapperUtils");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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 = (0, _wrapperUtils.parseBooleanAttr)(parentAccordion?.getAttribute('bordered'));
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Accordion.AccordionItem, {
    ...otherProps,
    defaultOpen: (0, _wrapperUtils.parseBooleanAttr)(defaultOpen),
    id: contentId,
    contentClassName: (0, _classnames.default)(contentClassName, bordered && 'ds-c-accordion__content--bordered')
  });
};
(0, _define.define)('ds-accordion-item', () => Wrapper, {
  attributes,
  events: ['onChange'],
  shadow: true,
  passCustomElementProp: true
});