content: import _defineProperty from 'babel-runtime/helpers/defineProperty';
  import { setTransform, isTransformSupported } from './utils';
  import React from 'react';
  import classnames from 'classnames';
  
  export function getScroll(w, top) {
    var ret = w['page' + (top ? 'Y' : 'X') + 'Offset'];
    var method = 'scroll' + (top ? 'Top' : 'Left');
    if (typeof ret !== 'number') {
      var d = w.document;
      // ie6,7,8 standard mode
      ret = d.documentElement[method];
      if (typeof ret !== 'number') {
        // quirks mode
        ret = d.body[method];
      }
    }
    return ret;
  }
  
  function offset(elem) {
    var box = void 0;
    var x = void 0;
    var y = void 0;
    var doc = elem.ownerDocument;
    var body = doc.body;
    var docElem = doc && doc.documentElement;
    box = elem.getBoundingClientRect();
    x = box.left;
    y = box.top;
    x -= docElem.clientLeft || body.clientLeft || 0;
    y -= docElem.clientTop || body.clientTop || 0;
    var w = doc.defaultView || doc.parentWindow;
    x += getScroll(w);
    y += getScroll(w, true);
    return {
      left: x, top: y
    };
  }
  
  function _componentDidUpdate(component, init) {
    var refs = component.refs;
    var styles = component.props.styles;
  
    var wrapNode = refs.nav || refs.root;
    var containerOffset = offset(wrapNode);
    var inkBarNode = refs.inkBar;
    var activeTab = refs.activeTab;
    var inkBarNodeStyle = inkBarNode.style;
    var tabBarPosition = component.props.tabBarPosition;
    if (init) {
      // prevent mount animation
      inkBarNodeStyle.display = 'none';
    }
    if (activeTab) {
      var tabNode = activeTab;
      var tabOffset = offset(tabNode);
      var transformSupported = isTransformSupported(inkBarNodeStyle);
      if (tabBarPosition === 'top' || tabBarPosition === 'bottom') {
        var left = tabOffset.left - containerOffset.left;
        var width = tabNode.offsetWidth;
        if (styles.inkBar && styles.inkBar.width !== undefined) {
          width = parseFloat(styles.inkBar.width, 10);
          if (width) {
            left = left + (tabNode.offsetWidth - width) / 2;
          }
        }
        // use 3d gpu to optimize render
        if (transformSupported) {
          setTransform(inkBarNodeStyle, 'translate3d(' + left + 'px,0,0)');
          inkBarNodeStyle.width = width + 'px';
          inkBarNodeStyle.height = '';
        } else {
          inkBarNodeStyle.left = left + 'px';
          inkBarNodeStyle.top = '';
          inkBarNodeStyle.bottom = '';
          inkBarNodeStyle.right = wrapNode.offsetWidth - left - width + 'px';
        }
      } else {
        var top = tabOffset.top - containerOffset.top;
        var height = tabNode.offsetHeight;
        if (styles.inkBar && styles.inkBar.height !== undefined) {
          height = parseFloat(styles.inkBar.height, 10);
          if (height) {
            top = top + (tabNode.offsetHeight - height) / 2;
          }
        }
        if (transformSupported) {
          setTransform(inkBarNodeStyle, 'translate3d(0,' + top + 'px,0)');
          inkBarNodeStyle.height = height + 'px';
          inkBarNodeStyle.width = '';
        } else {
          inkBarNodeStyle.left = '';
          inkBarNodeStyle.right = '';
          inkBarNodeStyle.top = top + 'px';
          inkBarNodeStyle.bottom = wrapNode.offsetHeight - top - height + 'px';
        }
      }
    }
    inkBarNodeStyle.display = activeTab ? 'block' : 'none';
  }
  
  export default {
    getDefaultProps: function getDefaultProps() {
      return {
        inkBarAnimated: true
      };
    },
    componentDidUpdate: function componentDidUpdate() {
      _componentDidUpdate(this);
    },
    componentDidMount: function componentDidMount() {
      _componentDidUpdate(this, true);
    },
    getInkBarNode: function getInkBarNode() {
      var _classnames;
  
      var _props = this.props,
          prefixCls = _props.prefixCls,
          styles = _props.styles,
          inkBarAnimated = _props.inkBarAnimated;
  
      var className = prefixCls + '-ink-bar';
      var classes = classnames((_classnames = {}, _defineProperty(_classnames, className, true), _defineProperty(_classnames, inkBarAnimated ? className + '-animated' : className + '-no-animated', true), _classnames));
      return React.createElement('div', {
        style: styles.inkBar,
        className: classes,
        key: 'inkBar',
        ref: 'inkBar'
      });
    }
  };