import _zipWith from "lodash/fp/zipWith";
import _constant from "lodash/fp/constant";
import _identity from "lodash/fp/identity";
import _getOr from "lodash/fp/getOr";
import _get from "lodash/fp/get";
import _set from "lodash/fp/set";
import _pipe from "lodash/fp/pipe";
import _map from "lodash/fp/map";
import React from 'react';
import PropTypes from 'prop-types';
import Accordion from '../container';
class AccordionToggler extends React.Component {
  static getDerivedStateFromProps(props, state) {
    if (state.isOpenValues && state.isOpenValues.length === props.tabProps.length) return null;
    const isOpenValues = _map(_getOr(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: _pipe(oneTabOnly ? _map(_constant(false)) : _identity, _set(key, !_get(key, prevState.isOpenValues)))(prevState.isOpenValues)
      };
    });
  }
  mergePropsAndState() {
    const {
      tabProps
    } = this.props;
    const {
      isOpenValues
    } = this.state;
    return _zipWith((props, isOpen) => ({
      ...props,
      isOpen
    }), tabProps, isOpenValues);
  }
  render() {
    const {
      children = [],
      theme
    } = this.props;
    return /*#__PURE__*/React.createElement(Accordion, {
      tabProps: this.mergePropsAndState(),
      onClick: this.handleOnClick,
      theme: theme
    }, children);
  }
}
AccordionToggler.propTypes = process.env.NODE_ENV !== "production" ? {
  tabProps: PropTypes.arrayOf(PropTypes.shape(Accordion.propTypes)),
  oneTabOnly: PropTypes.bool,
  theme: PropTypes.string,
  children: PropTypes.node
} : {};
export default AccordionToggler;
//# sourceMappingURL=index.js.map