'use strict';

require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/web.dom-collections.for-each.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _extends = require('@babel/runtime/helpers/extends');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var react = require('@carbon/react');
var PropTypes = require('prop-types');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

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__default.default(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__default.default(_ref, _excluded);
  var open = props.open;
  var _useState = React.useState(open),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    openState = _useState2[0],
    setOpenState = _useState2[1];
  var _useState3 = React.useState(open),
    _useState4 = _slicedToArray__default.default(_useState3, 2),
    hasEverBeenOpened = _useState4[0],
    setHasEverBeenOpened = _useState4[1];
  React.useEffect(function () {
    setOpenState(open);
  }, [open]);
  var handleToggle = function handleToggle(event) {
    if (props.onHeadingClick) {
      props.onHeadingClick(event);
    }
    setOpenState(!openState);
    setHasEverBeenOpened(true);
  };
  return /*#__PURE__*/React__default.default.createElement(react.AccordionItem, _extends__default.default({
    "data-testid": testId
  }, props, {
    onHeadingClick: handleToggle
  }), openState && children || hasEverBeenOpened && children);
};
AccordionItemDefer.propTypes = _objectSpread(_objectSpread({}, react.AccordionItem.propTypes), {}, {
  testId: PropTypes__default.default.string
});
AccordionItemDefer.defaultProps = _objectSpread(_objectSpread({}, react.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;

module.exports = AccordionItemDefer$1;
