import { Children } from 'react';
import CSSTranslate from './CSSTranslate';
export var noop = function noop() {};
export var defaultStatusFormatter = function defaultStatusFormatter(current, total) {
  return "".concat(current, " of ").concat(total);
};
export var isKeyboardEvent = function isKeyboardEvent(e) {
  return e ? e.hasOwnProperty('key') : false;
};

/**
 * Gets the list 'position' relative to a current index
 * @param index
 */
export var getPosition = function getPosition(index, props) {
  if (props.infiniteLoop) {
    // index has to be added by 1 because of the first cloned slide
    ++index;
  }
  if (index === 0) {
    return 0;
  }
  var childrenLength = Children.count(props.children);
  if (props.centerMode && props.axis === 'horizontal') {
    var currentPosition = -index * props.centerSlidePercentage;
    var lastPosition = childrenLength - 1;
    if (index && (index !== lastPosition || props.infiniteLoop)) {
      currentPosition += (100 - props.centerSlidePercentage) / 2;
    } else if (index === lastPosition) {
      currentPosition += 100 - props.centerSlidePercentage;
    }
    return currentPosition;
  }
  return -index * 100;
};

/**
 * Sets the 'position' transform for sliding animations
 * @param position
 * @param forceReflow
 */
export var setPosition = function setPosition(position, axis) {
  var style = {};
  ['WebkitTransform', 'MozTransform', 'MsTransform', 'OTransform', 'transform', 'msTransform'].forEach(function (prop) {
    // @ts-ignore
    style[prop] = CSSTranslate(position, '%', axis);
  });
  return style;
};