"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AccordionItemHead = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Accordion = require("./Accordion");
var _AccordionItem = require("./AccordionItem");
var _Styles = require("./Styles");
var _CollapseExpandSingle = _interopRequireDefault(require("../Icons/collection/CollapseExpandSingle"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var AccordionItemHead = exports.AccordionItemHead = function AccordionItemHead(_ref) {
  var children = _ref.children,
    className = _ref.className;
  var accordionContext = (0, _react.useContext)(_Accordion.AccordionContext);
  var itemContext = (0, _react.useContext)(_AccordionItem.ItemContext);
  var _useMemo = (0, _react.useMemo)(function () {
      return {
        toggleExpanded: accordionContext ? accordionContext.toggleExpanded : null,
        disableToggleIcon: accordionContext ? accordionContext.disableToggleIcon : false,
        customToggleIcon: accordionContext ? accordionContext.customToggleIcon : null
      };
    }, [accordionContext]),
    toggleExpanded = _useMemo.toggleExpanded,
    disableToggleIcon = _useMemo.disableToggleIcon,
    customToggleIcon = _useMemo.customToggleIcon;
  var id = (0, _react.useMemo)(function () {
    return itemContext ? itemContext.id : "";
  }, [itemContext]);
  var onClickCallback = (0, _react.useCallback)(function () {
    if (toggleExpanded) {
      toggleExpanded(id);
    }
  }, [id, toggleExpanded]);
  var toggleIcon = (0, _react.useMemo)(function () {
    return customToggleIcon ? customToggleIcon : /*#__PURE__*/_react.default.createElement(_CollapseExpandSingle.default, {
      style: {
        transform: "rotate(180deg)"
      }
    });
  }, [customToggleIcon]);
  return /*#__PURE__*/_react.default.createElement(_Styles.StyledAccordionItemHead, {
    onClick: onClickCallback,
    className: (0, _classnames.default)("accordionItemHead", className)
  }, /*#__PURE__*/_react.default.createElement(_Styles.StyledAccordionItemHeadText, {
    className: "accordionItemHead__text"
  }, children), /*#__PURE__*/_react.default.createElement(_Styles.StyledAccordionItemHeadIcon, {
    className: "accordionItemHead__icon"
  }, !disableToggleIcon ? toggleIcon : null));
};
AccordionItemHead.displayName = "AccordionItemHead";
//# sourceMappingURL=AccordionItemHead.js.map