'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isFadeOutAnimationAllowed = exports.isAnimatedItem = exports.getTranslate3dPosition = undefined;

(function () {
  var enterModule = require('react-hot-loader').enterModule;

  enterModule && enterModule(module);
})();

exports.animate = animate;
exports.getTranslateX = getTranslateX;
exports.getTransformMatrix = getTransformMatrix;

var _elements = require('./elements');

function animate(element) {
  var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  var durationMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;

  if ((0, _elements.isElement)(element)) {
    element.style['transition'] = 'transform ' + durationMs + 'ms ease-out';
    element.style['transform'] = 'translate3d(' + position + 'px, 0, 0)';
  }
  return element;
}

function getTranslateX(element) {
  var translateXIndex = 4;
  var matrix = getTransformMatrix(element);
  return matrix[translateXIndex] || '';
}

function getTransformMatrix(element) {
  if ((0, _elements.isElement)(element)) {
    var _ref = getComputedStyle(element) || {},
        _ref$transform = _ref.transform,
        transform = _ref$transform === undefined ? '' : _ref$transform;

    var matched = transform.match(/[0-9., -]+/) || [];
    if (typeof matched[0] === 'string') {
      return matched[0].split(',');
    }
  }
  return [];
}

var getTranslate3dPosition = exports.getTranslate3dPosition = function getTranslate3dPosition() {
  var currentIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var itemWidth = state.itemWidth,
      items = state.items,
      infinite = state.infinite,
      _state$stagePadding = state.stagePadding,
      stagePadding = _state$stagePadding === undefined ? {} : _state$stagePadding;


  if (infinite) {
    var paddingLeft = stagePadding.paddingLeft,
        paddingRight = stagePadding.paddingRight;

    if (paddingLeft || paddingRight) {
      currentIndex += 1;
    }
  }

  return (items + currentIndex) * -itemWidth || 0;
};

var isAnimatedItem = exports.isAnimatedItem = function isAnimatedItem() {
  var i = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  var animationProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var allowFadeOutAnimation = animationProps.allowFadeOutAnimation,
      fadeOutIndex = animationProps.fadeOutIndex;

  return !!allowFadeOutAnimation && fadeOutIndex === i;
};

var isFadeOutAnimationAllowed = exports.isFadeOutAnimationAllowed = function isFadeOutAnimationAllowed() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var stagePadding = state.stagePadding,
      items = state.items;

  var hasNoStagePadding = !(stagePadding.paddingLeft || stagePadding.paddingRight);

  return props.fadeOutAnimation && items === 1 && hasNoStagePadding;
};
;

(function () {
  var reactHotLoader = require('react-hot-loader').default;

  var leaveModule = require('react-hot-loader').leaveModule;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(animate, 'animate', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/animation.js');
  reactHotLoader.register(getTranslateX, 'getTranslateX', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/animation.js');
  reactHotLoader.register(getTransformMatrix, 'getTransformMatrix', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/animation.js');
  reactHotLoader.register(getTranslate3dPosition, 'getTranslate3dPosition', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/animation.js');
  reactHotLoader.register(isAnimatedItem, 'isAnimatedItem', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/animation.js');
  reactHotLoader.register(isFadeOutAnimationAllowed, 'isFadeOutAnimationAllowed', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/animation.js');
  leaveModule(module);
})();

;