function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/*
Copyright (c) 2018-2019 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
export default class StatefulContainer extends React.Component {
  constructor(props) {
    super(props);

    _defineProperty(this, "state", void 0);

    _defineProperty(this, "onToggle", node => {
      const {
        onToggle
      } = this.props;
      this.setState(prevState => {
        node.isExpanded = !node.isExpanded;
        return {
          data: prevState.data
        };
      }, () => {
        onToggle && onToggle(node);
      });
    });

    this.state = {
      data: this.props.data
    };
  }

  render() {
    const {
      children,
      ...restProps
    } = this.props;
    const {
      onToggle
    } = this;
    return children({ ...restProps,
      ...this.state,
      onToggle
    });
  }

}