import React__default, { useState } from 'react';
import Icon, { IconTypes } from './Icon.js';
import AccordionGroup$1 from './AccordionGroup.js';
import { C as Consumer } from '../context-8712877d.js';
import 'prop-types';
import '../utils-b53fe532.js';

function Accordion(_ref) {
  let {
    className,
    id,
    renderTitle,
    renderContent,
    renderFooter
  } = _ref;
  const [showAccordion, setShowAccordion] = useState(false);
  return /*#__PURE__*/React__default.createElement(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.createElement(React__default.Fragment, null, /*#__PURE__*/React__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.createElement(Icon, {
      type: 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.createElement("div", {
      className: "sendbird-accordion"
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "sendbird-accordion__list"
    }, renderContent()), renderFooter && /*#__PURE__*/React__default.createElement("div", {
      className: "sendbird-accordion__footer"
    }, renderFooter())));
  });
}
const AccordionGroup = AccordionGroup$1;

export { AccordionGroup, Accordion as default };
//# sourceMappingURL=Accordion.js.map
