'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var ui_Icon = require('./Icon.js');
var ui_AccordionGroup = require('./AccordionGroup.js');
var context = require('../context-2bf3186e.js');
require('prop-types');
require('../utils-6a748c02.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

function Accordion(_ref) {
  let {
    className,
    id,
    renderTitle,
    renderContent,
    renderFooter
  } = _ref;
  const [showAccordion, setShowAccordion] = React.useState(false);
  return /*#__PURE__*/React__default["default"].createElement(context.Consumer, null,
  // Function is considered like a react component
  value => {
    const {
      opened,
      setOpened
    } = value; // props from Provider
    if (id === opened) {
      setShowAccordion(true);
    } else {
      setShowAccordion(false);
    }
    const handleClick = () => {
      if (showAccordion) {
        setOpened('');
      } else {
        setOpened(id);
      }
    };
    return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
      className: [...(Array.isArray(className) ? className : [className]), 'sendbird-accordion__panel-header'].join(' '),
      id: id,
      role: "switch",
      "aria-checked": false,
      onClick: handleClick,
      onKeyDown: handleClick,
      tabIndex: 0
    }, renderTitle(), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: ui_Icon.IconTypes.CHEVRON_RIGHT,
      className: ['sendbird-accordion__panel-icon-right', 'sendbird-accordion__panel-icon--chevron', showAccordion ? 'sendbird-accordion__panel-icon--open' : ''].join(' '),
      height: "24px",
      width: "24px"
    })), showAccordion && /*#__PURE__*/React__default["default"].createElement("div", {
      className: "sendbird-accordion"
    }, /*#__PURE__*/React__default["default"].createElement("div", {
      className: "sendbird-accordion__list"
    }, renderContent()), renderFooter && /*#__PURE__*/React__default["default"].createElement("div", {
      className: "sendbird-accordion__footer"
    }, renderFooter())));
  });
}
const AccordionGroup = ui_AccordionGroup;

exports.AccordionGroup = AccordionGroup;
exports["default"] = Accordion;
//# sourceMappingURL=Accordion.js.map
