"use strict";

require("core-js/modules/es.object.assign.js");
require("core-js/modules/es.weak-map.js");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CoalitionCarouselItem = exports.CoalitionCarousel = void 0;
require("core-js/modules/web.dom-collections.iterator.js");
var _react = _interopRequireWildcard(require("react"));
var _reactSwipeable = require("react-swipeable");
require("./CoalitionCarousel.css");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
const CoalitionCarousel = _ref => {
  let {
    children
  } = _ref;
  const [activeIndex, setActiveIndex] = (0, _react.useState)(0);
  const [paused, setPaused] = (0, _react.useState)(false);
  const setIdx = newIndex => {
    if (newIndex < 0) {
      newIndex = _react.default.Children.count(children) - 1;
    } else if (newIndex >= _react.default.Children.count(children)) {
      newIndex = 0;
    }
    setActiveIndex(newIndex);
  };
  (0, _react.useEffect)(() => {
    const interval = setInterval(() => {
      if (!paused) setIdx(activeIndex + 1);
    }, 3000);
    return () => {
      if (interval) clearInterval(interval);
    };
  });
  const handlers = (0, _reactSwipeable.useSwipeable)({
    onSwipedLeft: () => setIdx(activeIndex + 1),
    onSwipedRight: () => setIdx(activeIndex - 1)
  });
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-carousel"
  }, /*#__PURE__*/_react.default.createElement("div", _extends({}, handlers, {
    className: "coalition-carousel-handler",
    onMouseEnter: () => setPaused(true),
    onMouseLeave: () => setPaused(false)
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-carousel-handler-inner",
    style: {
      transform: "translateX(-".concat(activeIndex * 100, "%)")
    }
  }, _react.default.Children.map(children, (child, _) => /*#__PURE__*/_react.default.cloneElement(child, {
    width: "100%"
  }))), /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-carousel-handler-indicators"
  }, /*#__PURE__*/_react.default.createElement("button", {
    onClick: () => setIdx(activeIndex - 1),
    className: "coalition-carousel-handler-indicators-button"
  }, "<"), _react.default.Children.map(children, (_, index) => {
    return /*#__PURE__*/_react.default.createElement("button", {
      className: "".concat(index === activeIndex ? "active" : ""),
      style: {
        cursor: "pointer"
      },
      onClick: () => setIdx(index)
    });
  }), /*#__PURE__*/_react.default.createElement("button", {
    onClick: () => setIdx(activeIndex + 1),
    className: "coalition-carousel-handler-indicators-button"
  }, ">"))));
};
exports.CoalitionCarousel = CoalitionCarousel;
const CoalitionCarouselItem = _ref2 => {
  let {
    children,
    width
  } = _ref2;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-carousel-handler-carousel-item",
    style: {
      width: width
    }
  }, children);
};
exports.CoalitionCarouselItem = CoalitionCarouselItem;