text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.CLASS_NAME = undefined;
  
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  
  var _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _propTypes = require('prop-types');
  
  var _propTypes2 = _interopRequireDefault(_propTypes);
  
  var _autoBind = require('@zippytech/react-class/autoBind');
  
  var _autoBind2 = _interopRequireDefault(_autoBind);
  
  var _join = require('./join');
  
  var _join2 = _interopRequireDefault(_join);
  
  var _raf = require('../../common/raf');
  
  var _raf2 = _interopRequireDefault(_raf);
  
  var _shouldComponentUpdate2 = require('../../common/shouldComponentUpdate');
  
  var _shouldComponentUpdate3 = _interopRequireDefault(_shouldComponentUpdate2);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  * Copyright (c) 2015-present, Zippy Technologies
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  * This source code is licensed under the MIT license found in the
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  * LICENSE file in the root directory of this source tree.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  */
  
  var CLASS_NAME = exports.CLASS_NAME = 'zippy-react-toolkit-accordion__tab-content';
  
  var returnFalse = function returnFalse() {
    return false;
  };
  
  var absolutePositionerStyle = {
    position: 'absolute'
  };
  
  var AccordionTabContentComponent = function (_Component) {
    _inherits(AccordionTabContentComponent, _Component);
  
    function AccordionTabContentComponent() {
      _classCallCheck(this, AccordionTabContentComponent);
  
      return _possibleConstructorReturn(this, (AccordionTabContentComponent.__proto__ || Object.getPrototypeOf(AccordionTabContentComponent)).apply(this, arguments));
    }
  
    _createClass(AccordionTabContentComponent, [{
      key: 'shouldComponentUpdate',
      value: function shouldComponentUpdate(nextProps, nextState) {
        return (0, _shouldComponentUpdate3.default)(this, nextProps, nextState);
      }
    }, {
      key: 'render',
      value: function render() {
        var props = _extends({}, this.props);
        delete props.shouldComponentUpdate;
        return _react2.default.createElement('div', props);
      }
    }]);
  
    return AccordionTabContentComponent;
  }(_react.Component);
  
  var ZippyAccordionTabContent = function (_Component2) {
    _inherits(ZippyAccordionTabContent, _Component2);
  
    function ZippyAccordionTabContent(props) {
      _classCallCheck(this, ZippyAccordionTabContent);
  
      var _this2 = _possibleConstructorReturn(this, (ZippyAccordionTabContent.__proto__ || Object.getPrototypeOf(ZippyAccordionTabContent)).call(this, props));
  
      (0, _autoBind2.default)(_this2);
      _this2.state = {
        inTransition: false,
  
        startingWidth: null,
        finalWidth: null,
  
        startingHeight: null,
        finalHeight: null
      };
      return _this2;
    }
  
    _createClass(ZippyAccordionTabContent, [{
      key: '_transitionHeightFromTo',
      value: function _transitionHeightFromTo(start, end) {
        var _this3 = this;
  
        var raf = this.props.raf;
  
        this.willTransition = true;
        this.setState({
          startingHeight: start
        });
  
        raf(function () {
          _this3.setState({
            finalHeight: end,
            inTransition: true
          }, function () {
            raf(function () {
              _this3.setState({ startingHeight: null });
              _this3._expandInProgress = false;
            });
          });
        });
      }
    }, {
      key: '_transitionWidthFromTo',
      value: function _transitionWidthFromTo(start, end) {
        var _this4 = this;
  
        var raf = this.props.raf;
  
        this.willTransition = true;
        this.setState({
          startingWidth: start
        });
  
        raf(function () {
          _this4.setState({
            finalWidth: end,
            inTransition: true
          }, function () {
            raf(function () {
              _this4.willTransition = false;
              _this4.setState({ startingWidth: null });
              _this4._expandInProgress = false;
            });
          });
        });
      }
    }, {
      key: '_handleVerticalExpand',
      value: function _handleVerticalExpand(expanded, expandedHeight) {
        var startingHeight = void 0,
            finalHeight = void 0;
  
        if (expanded) {
          startingHeight = 0;
          finalHeight = expandedHeight || this.getContentHeight();
        } else {
          startingHeight = expandedHeight || this.getContentHeight();
          finalHeight = 0;
        }
  
        this._expandInProgress = true;
        this._transitionHeightFromTo(startingHeight, finalHeight);
      }
    }, {
      key: '_handleHorizontalExpand',
      value: function _handleHorizontalExpand(expanded, expandedWidth) {
        var startingWidth = void 0,
            finalWidth = void 0;
  
        if (expanded) {
          startingWidth = 0;
          finalWidth = expandedWidth || this.getContentWidth();
        } else {
          startingWidth = expandedWidth || this.getContentWidth();
          finalWidth = 0;
        }
  
        this._expandInProgress = true;
        this._transitionWidthFromTo(startingWidth, finalWidth);
      }
    }, {
      key: 'componentDidUpdate',
      value: function componentDidUpdate(prevProps) {
        var _props = this.props,
            expanded = _props.expanded,
            orientation = _props.orientation,
            transition = _props.transition,
            expandedHeight = _props.expandedHeight,
            expandedWidth = _props.expandedWidth;
        var oldExpanded = prevProps.expanded;
  
  
        if (expanded !== oldExpanded) {
          if (transition) {
            if (orientation === 'vertical') {
              this._handleVerticalExpand(expanded, expandedHeight);
            } else {
              this._handleHorizontalExpand(expanded, expandedWidth);
            }
  
            this._callTransitionStartCallbacks();
          } else {
            this._callTransitionCallbacks(this.props);
          }
        }
      }
    }, {
      key: '_callTransitionStartCallbacks',
      value: function _callTransitionStartCallbacks(props) {
        var _ref = props || this.props,
            expanded = _ref.expanded,
            onExpandStart = _ref.onExpandStart,
            onCollapseStart = _ref.onCollapseStart;
  
        if (expanded) {
          onExpandStart && onExpandStart();
        } else {
          onCollapseStart && onCollapseStart();
        }
      }
    }, {
      key: '_callTransitionCallbacks',
      value: function _callTransitionCallbacks(props) {
        this.willTransition = false;
  
        var _ref2 = props || this.props,
            expanded = _ref2.expanded,
            orientation = _ref2.orientation,
            onExpandEnd = _ref2.onExpandEnd,
            onCollapseEnd = _ref2.onCollapseEnd;
  
        if (expanded) {
          onExpandEnd && onExpandEnd();
        } else {
          onCollapseEnd && onCollapseEnd();
        }
      }
    }, {
      key: 'onTransitionEnd',
      value: function onTransitionEnd() {
        var _this5 = this;
  
        var raf = this.props.raf;
  
        raf(function () {
          _this5.setState({
            inTransition: false,
            finalHeight: null,
            finalWidth: null
          }, _this5._callTransitionCallbacks);
        });
      }
    }, {
      key: 'getHeight',
      value: function getHeight() {
        return this.refs.innerContent.offsetHeight;
      }
    }, {
      key: 'getWidth',
      value: function getWidth() {
        return this.refs.innerContent.offsetWidth;
      }
  
      //height might be 0 or some fancy value given by tabStyle padding
  
    }, {
      key: 'getContentHeight',
      value: function getContentHeight() {
        return this.refs.innerContent.children[0].offsetHeight;
      }
    }, {
      key: 'getContentWidth',
      value: function getContentWidth() {
        return this.refs.innerContent.children[0].offsetWidth;
      }
  
      // applied to the wrapper that collapses or expands
  
    }, {
      key: 'getComputedContainerStyles',
      value: function getComputedContainerStyles() {
        var transition = this.props.transition;
  
  
        if (!transition) {
          return {};
        }
  
        var _state = this.state,
            inTransition = _state.inTransition,
            startingHeight = _state.startingHeight,
            finalHeight = _state.finalHeight,
            startingWidth = _state.startingWidth,
            finalWidth = _state.finalWidth;
        var _props2 = this.props,
            orientation = _props2.orientation,
            multiExpand = _props2.multiExpand,
            transitionDuration = _props2.transitionDuration,
            transitionFunction = _props2.transitionFunction;
  
        // animation flicker hack. Because raf might not set transition state
        // with the frist call to render, we might end up with expanded true
        // but no animation or fixed heights/widths to animate to/from.
  
        var expanded = this.props.expanded;
  
        if (this._expandInProgress) {
          expanded = !expanded;
        }
  
        var computedContainerStyle = {};
        var inTransitionContentStyle = {
          transitionDuration: transitionDuration + 'ms',
          transitionTimingFunction: transitionFunction
        };
  
        if (startingHeight !== null) {
          computedContainerStyle.height = startingHeight;
        } else if (startingWidth !== null) {
          computedContainerStyle.width = startingWidth;
        } else {
          if (inTransition) {
            if (orientation === 'horizontal') {
              computedContainerStyle = _extends({
                width: finalWidth
              }, inTransitionContentStyle);
            } else {
              computedContainerStyle = _extends({
                height: finalHeight
              }, inTransitionContentStyle);
            }
          }
        }
  
        return computedContainerStyle;
      }
  
      // applied to the wrapper that keeps the dimmensions of the content while
      // the transition happens (preventing reflows)
  
    }, {
      key: 'getComputedScrollContainerStyle',
      value: function getComputedScrollContainerStyle() {
        var _props3 = this.props,
            orientation = _props3.orientation,
            expandedHeight = _props3.expandedHeight,
            expandedWidth = _props3.expandedWidth;
        var _state2 = this.state,
            inTransition = _state2.inTransition,
            finalHeight = _state2.finalHeight,
            finalWidth = _state2.finalWidth;
  
        var contentScrollWrapperStyle = {};
        if (inTransition || this._expandInProgress) {
          contentScrollWrapperStyle = _extends({}, absolutePositionerStyle);
          if (orientation === 'vertical') {
            contentScrollWrapperStyle.height = finalHeight || expandedHeight;
          } else {
            contentScrollWrapperStyle.width = finalWidth || expandedWidth;
            contentScrollWrapperStyle.bottom = 0;
          }
        }
        return contentScrollWrapperStyle;
      }
    }, {
      key: 'getClassNames',
      value: function getClassNames() {
        var _props4 = this.props,
            className = _props4.className,
            expanded = _props4.expanded,
            transition = _props4.transition,
            firstTab = _props4.firstTab,
            lastTab = _props4.lastTab,
            rootClassName = _props4.rootClassName,
            wrapperClassName = _props4.wrapperClassName;
        var inTransition = this.state.inTransition;
  
  
        var lastExpandedState = expanded;
        if (this._expandInProgress) {
          lastExpandedState = !expanded;
        }
  
        return (0, _join2.default)(className, rootClassName, wrapperClassName, lastExpandedState ? rootClassName + '--expanded' : rootClassName + '--collapsed', transition && inTransition && rootClassName + '--intransition', firstTab && rootClassName + '--first', lastTab && rootClassName + '--last');
      }
    }, {
      key: 'render',
      value: function render() {
        var _props5 = this.props,
            idx = _props5.idx,
            wrapperStyle = _props5.wrapperStyle,
            rootClassName = _props5.rootClassName,
            scrollTabContent = _props5.scrollTabContent;
        var forceWrapperReflow = this.state.forceWrapperReflow;
  
  
        var sCU = this.willTransition ? returnFalse : null;
  
        return _react2.default.createElement(
          'div',
          {
            className: this.getClassNames(),
            ref: 'tabContent',
            style: this.getComputedContainerStyles(),
            onTransitionEnd: this.onTransitionEnd,
            onMouseDown: this.props.onWrapperMouseDown
          },
          _react2.default.createElement(
            'div',
            {
              className: rootClassName + '__scroll-wrapper',
              style: _extends({}, this.getComputedScrollContainerStyle()),
              ref: 'innerContent'
            },
            _react2.default.createElement(
              AccordionTabContentComponent,
              {
                shouldComponentUpdate: sCU,
                className: (0, _join2.default)(rootClassName + '__content-wrapper', scrollTabContent && rootClassName + '__content-wrapper--scroll-tab-content', forceWrapperReflow && 'fx-force-flex-reflow'),
                style: wrapperStyle
              },
              this.props.children
            )
          )
        );
      }
    }]);
  
    return ZippyAccordionTabContent;
  }(_react.Component);
  
  ZippyAccordionTabContent.defaultProps = {
    expanded: false,
    orientation: 'vertical',
  
    transitionFunction: 'ease',
    transitionDuration: 300,
    transition: true,
  
    raf: _raf2.default,
    rootClassName: CLASS_NAME
  };
  
  ZippyAccordionTabContent.propTypes = {
    shouldComponentUpdate: _propTypes2.default.func,
    children: _propTypes2.default.any,
  
    scrollTabContent: _propTypes2.default.bool,
  
    expanded: _propTypes2.default.bool,
    nextAfterExpanded: _propTypes2.default.bool,
    orientation: _propTypes2.default.oneOf(['vertical', 'horizontal']),
  
    wrapperStyle: _propTypes2.default.object,
    wrapperClassName: _propTypes2.default.string,
  
    transition: _propTypes2.default.bool,
    transitionDuration: _propTypes2.default.number,
    transitionFunction: _propTypes2.default.string,
  
    expandedWidth: _propTypes2.default.number,
    expandedHeight: _propTypes2.default.number,
  
    onExpandStart: _propTypes2.default.func,
    onExpandEnd: _propTypes2.default.func,
  
    onCollapseStart: _propTypes2.default.func,
    onCollapseEnd: _propTypes2.default.func,
    raf: _propTypes2.default.func,
    rootClassName: _propTypes2.default.string
  };
  
  exports.default = ZippyAccordionTabContent;