'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.calculateInitialProps = exports.setTotalItemsInSlide = undefined;

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

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

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

var _animation = require('./animation');

var _style = require('./style');

var _math = require('./math');

var setTotalItemsInSlide = exports.setTotalItemsInSlide = function setTotalItemsInSlide(responsiveConfig, childrenLength) {
  var items = 1;
  if (responsiveConfig) {
    var configKeys = Object.keys(responsiveConfig);

    if (configKeys.length) {
      configKeys.forEach(function (width) {
        if (width < window.innerWidth) {
          items = Math.min(responsiveConfig[width].items, childrenLength) || items;
        }
      });
    }
  }
  return items;
};

var calculateInitialProps = exports.calculateInitialProps = function calculateInitialProps(props, rootComponent) {
  var startIndex = props.startIndex,
      responsive = props.responsive,
      infinite = props.infinite;

  var style = (0, _style.getDefaultStyle)();
  var slides = (0, _elements.getSlides)(props);
  var stagePadding = (0, _elements.getStagePadding)(props);
  var items = setTotalItemsInSlide(responsive, slides.length);
  var currentIndex = (0, _math.setStartIndex)(slides.length, startIndex);
  var galleryWidth = (0, _elements.getElementWidth)(rootComponent);
  var itemWidth = (0, _elements.getItemWidth)(galleryWidth, items);
  var clones = (0, _elements.cloneCarouselItems)(slides, items, { stagePadding: stagePadding, infinite: infinite });
  var translate3d = (0, _animation.getTranslate3dPosition)(currentIndex, { itemWidth: itemWidth, items: items, stagePadding: stagePadding, infinite: infinite });

  return {
    items: items,
    itemWidth: itemWidth,
    currentIndex: currentIndex,
    slides: slides,
    clones: clones,
    infinite: infinite,
    translate3d: translate3d,
    stagePadding: stagePadding,
    style: style
  };
};
;

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

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

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(setTotalItemsInSlide, 'setTotalItemsInSlide', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/common.js');
  reactHotLoader.register(calculateInitialProps, 'calculateInitialProps', '/Users/mmarinich/WebstormProjects/react-alice-carousel/src/lib/utils/common.js');
  leaveModule(module);
})();

;