import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _extends from '@babel/runtime/helpers/extends';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default, { useState, useEffect } from 'react';
import { AccordionItem } from '@carbon/react';
import PropTypes from 'prop-types';

var _excluded = ["children", "testId"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var AccordionItemDefer = function AccordionItemDefer(_ref) {
  var children = _ref.children,
    testId = _ref.testId,
    props = _objectWithoutProperties(_ref, _excluded);
  var open = props.open;
  var _useState = useState(open),
    _useState2 = _slicedToArray(_useState, 2),
    openState = _useState2[0],
    setOpenState = _useState2[1];
  var _useState3 = useState(open),
    _useState4 = _slicedToArray(_useState3, 2),
    hasEverBeenOpened = _useState4[0],
    setHasEverBeenOpened = _useState4[1];
  useEffect(function () {
    setOpenState(open);
  }, [open]);
  var handleToggle = function handleToggle(event) {
    if (props.onHeadingClick) {
      props.onHeadingClick(event);
    }
    setOpenState(!openState);
    setHasEverBeenOpened(true);
  };
  return /*#__PURE__*/React__default.createElement(AccordionItem, _extends({
    "data-testid": testId
  }, props, {
    onHeadingClick: handleToggle
  }), openState && children || hasEverBeenOpened && children);
};
AccordionItemDefer.propTypes = _objectSpread(_objectSpread({}, AccordionItem.propTypes), {}, {
  testId: PropTypes.string
});
AccordionItemDefer.defaultProps = _objectSpread(_objectSpread({}, AccordionItem.defaultProps), {}, {
  testId: 'accordion-item-deferred'
});
AccordionItemDefer.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "AccordionItemDefer",
  "props": {
    "testId": {
      "defaultValue": {
        "value": "'accordion-item-deferred'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    }
  },
  "composes": ["@carbon/react"]
};
var AccordionItemDefer$1 = AccordionItemDefer;

export { AccordionItemDefer$1 as default };
