"use strict";

exports.__esModule = true;
exports.default = void 0;
var _zipWith2 = _interopRequireDefault(require("lodash/fp/zipWith"));
var _constant2 = _interopRequireDefault(require("lodash/fp/constant"));
var _identity2 = _interopRequireDefault(require("lodash/fp/identity"));
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
var _set2 = _interopRequireDefault(require("lodash/fp/set"));
var _pipe2 = _interopRequireDefault(require("lodash/fp/pipe"));
var _map2 = _interopRequireDefault(require("lodash/fp/map"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _container = _interopRequireDefault(require("../container"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
class AccordionToggler extends _react.default.Component {
  static getDerivedStateFromProps(props, state) {
    if (state.isOpenValues && state.isOpenValues.length === props.tabProps.length) return null;
    const isOpenValues = (0, _map2.default)((0, _getOr2.default)(false, 'isOpen'), props.tabProps);
    return {
      isOpenValues
    };
  }
  constructor(props) {
    super(props);
    this.state = {
      isOpenValues: null
    };
    this.handleOnClick = this.handleOnClick.bind(this);
  }
  handleOnClick(key) {
    const {
      oneTabOnly
    } = this.props;
    this.setState(prevState => {
      return {
        isOpenValues: (0, _pipe2.default)(oneTabOnly ? (0, _map2.default)((0, _constant2.default)(false)) : _identity2.default, (0, _set2.default)(key, !(0, _get2.default)(key, prevState.isOpenValues)))(prevState.isOpenValues)
      };
    });
  }
  mergePropsAndState() {
    const {
      tabProps
    } = this.props;
    const {
      isOpenValues
    } = this.state;
    return (0, _zipWith2.default)((props, isOpen) => ({
      ...props,
      isOpen
    }), tabProps, isOpenValues);
  }
  render() {
    const {
      children = [],
      theme
    } = this.props;
    return /*#__PURE__*/_react.default.createElement(_container.default, {
      tabProps: this.mergePropsAndState(),
      onClick: this.handleOnClick,
      theme: theme
    }, children);
  }
}
AccordionToggler.propTypes = process.env.NODE_ENV !== "production" ? {
  tabProps: _propTypes.default.arrayOf(_propTypes.default.shape(_container.default.propTypes)),
  oneTabOnly: _propTypes.default.bool,
  theme: _propTypes.default.string,
  children: _propTypes.default.node
} : {};
var _default = exports.default = AccordionToggler;
//# sourceMappingURL=index.js.map