text: "use strict";
  var __assign = (this && this.__assign) || function () {
      __assign = Object.assign || function(t) {
          for (var s, i = 1, n = arguments.length; i < n; i++) {
              s = arguments[i];
              for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                  t[p] = s[p];
          }
          return t;
      };
      return __assign.apply(this, arguments);
  };
  var __importStar = (this && this.__importStar) || function (mod) {
      if (mod && mod.__esModule) return mod;
      var result = {};
      if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
      result["default"] = mod;
      return result;
  };
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  var react_1 = __importStar(require("react"));
  var object_assign_1 = __importDefault(require("object-assign"));
  var utils_1 = require("./utils");
  var ReactIdSwiperCustom = function (props) {
      var Swiper = props.Swiper, activeSlideKey = props.activeSlideKey, ContainerEl = props.ContainerEl, children = props.children, containerClass = props.containerClass, getSwiper = props.getSwiper, navigation = props.navigation, noSwiping = props.noSwiping, pagination = props.pagination, parallax = props.parallax, parallaxEl = props.parallaxEl, WrapperEl = props.WrapperEl, wrapperClass = props.wrapperClass, rebuildOnUpdate = props.rebuildOnUpdate, renderScrollbar = props.renderScrollbar, renderPagination = props.renderPagination, renderPrevButton = props.renderPrevButton, renderNextButton = props.renderNextButton, renderParallax = props.renderParallax, rtl = props.rtl, scrollbar = props.scrollbar, shouldSwiperUpdate = props.shouldSwiperUpdate, slideClass = props.slideClass, loop = props.loop, _a = props.modules, modules = _a === void 0 ? [] : _a;
      // No render if wrapper elements are not provided or when modules is empty
      if (!Swiper || !children || !ContainerEl || !WrapperEl) {
          return null;
      }
      // Define swiper ref
      var swiperNodeRef = react_1.createRef();
      // Define swiper instance ref
      var swiperInstanceRef = react_1.useRef(null);
      // Initialize modules to use with swiper
      Swiper.use(modules);
      // Validate children props
      if (!utils_1.validateChildren(children)) {
          console.warn('Children should be react element or an array of react element!!');
          return null;
      }
      // Get current active slide key
      var getActiveSlideIndexFromProps = function () {
          if (!activeSlideKey) {
              return null;
          }
          var activeSlideId = 0;
          // In loop mode first slide index should be 1
          var id = loop ? 1 : 0;
          react_1.Children.forEach(children, function (child) {
              if (react_1.isValidElement(child)) {
                  if (child.key === activeSlideKey) {
                      activeSlideId = id;
                  }
                  id += 1;
              }
          });
          return activeSlideId;
      };
      // Get swiper instance
      var getSwiperInstance = function (swiperInstance) {
          if (typeof getSwiper === 'function') {
              getSwiper(swiperInstance);
          }
      };
      // Initialize swiper
      var buildSwiper = function () {
          if (swiperNodeRef.current && swiperInstanceRef.current === null) {
              swiperInstanceRef.current = new Swiper(swiperNodeRef.current, object_assign_1.default({}, props));
              getSwiperInstance(swiperInstanceRef.current);
          }
      };
      // Destroy swiper
      var destroySwiper = function () {
          if (swiperInstanceRef.current !== null) {
              swiperInstanceRef.current.destroy(true, true);
              swiperInstanceRef.current = null;
              getSwiperInstance(swiperInstanceRef.current);
          }
      };
      // Rebuild swiper
      var rebuildSwiper = function () {
          destroySwiper();
          buildSwiper();
      };
      // Update swiper
      var updateSwiper = function () {
          if (swiperInstanceRef.current !== null) {
              swiperInstanceRef.current.update();
              getSwiperInstance(swiperInstanceRef.current);
          }
      };
      // Render slides
      var renderContent = function (e) {
          if (!utils_1.isReactElement(e)) {
              return null;
          }
          var slideClassNames = [slideClass, e.props.className];
          if (noSwiping) {
              slideClassNames.push('swiper-no-swiping');
          }
          return react_1.cloneElement(e, __assign({}, e.props, { className: slideClassNames.join(' ').trim() }));
      };
      // Only execute when component is mounted or unmounted
      react_1.useEffect(function () {
          buildSwiper();
          var slideToIndex = getActiveSlideIndexFromProps();
          if (swiperInstanceRef.current !== null && slideToIndex !== null) {
              swiperInstanceRef.current.slideTo(slideToIndex);
          }
          return function () { return destroySwiper(); };
      }, []);
      // Execute each time when props are updated
      react_1.useEffect(function () {
          if (swiperInstanceRef.current !== null) {
              if (rebuildOnUpdate) {
                  rebuildSwiper();
              }
              else if (shouldSwiperUpdate) {
                  updateSwiper();
                  var numSlides = swiperInstanceRef.current.slides.length;
                  if (numSlides <= swiperInstanceRef.current.activeIndex) {
                      var index = Math.max(numSlides - 1, 0);
                      swiperInstanceRef.current.slideTo(index);
                  }
              }
              var slideToIndex = getActiveSlideIndexFromProps();
              if (slideToIndex !== null) {
                  swiperInstanceRef.current.slideTo(slideToIndex);
              }
          }
      });
      // Check modules are loaded before rendering contents
      var shouldRenderParallax = utils_1.isModuleAvailable(modules, 'parallax') && parallax && parallaxEl;
      var shouldRenderPagination = utils_1.isModuleAvailable(modules, 'pagination') && pagination && pagination.el;
      var shouldRenderScrollbar = utils_1.isModuleAvailable(modules, 'scrollbar') && scrollbar && scrollbar.el;
      var isNavigationModuleAvailable = utils_1.isModuleAvailable(modules, 'navigation');
      var shouldRenderNextButton = isNavigationModuleAvailable && navigation && navigation.nextEl;
      var shouldRenderPrevButton = isNavigationModuleAvailable && navigation && navigation.prevEl;
      return (react_1.default.createElement(ContainerEl, { className: containerClass, dir: rtl && 'rtl', ref: swiperNodeRef },
          shouldRenderParallax && renderParallax && renderParallax(props),
          react_1.default.createElement(WrapperEl, { className: wrapperClass }, react_1.Children.map(children, renderContent)),
          shouldRenderPagination && renderPagination && renderPagination(props),
          shouldRenderScrollbar && renderScrollbar && renderScrollbar(props),
          shouldRenderNextButton && renderNextButton && renderNextButton(props),
          shouldRenderPrevButton && renderPrevButton && renderPrevButton(props)));
  };
  // Default props
  ReactIdSwiperCustom.defaultProps = {
      containerClass: 'swiper-container',
      wrapperClass: 'swiper-wrapper',
      slideClass: 'swiper-slide',
      ContainerEl: 'div',
      WrapperEl: 'div',
      renderScrollbar: function (_a) {
          var scrollbar = _a.scrollbar;
          return scrollbar ? react_1.default.createElement("div", { className: utils_1.classNames(scrollbar.el) }) : null;
      },
      renderPagination: function (_a) {
          var pagination = _a.pagination;
          return pagination ? react_1.default.createElement("div", { className: utils_1.classNames(pagination.el) }) : null;
      },
      renderPrevButton: function (_a) {
          var navigation = _a.navigation;
          return navigation ? react_1.default.createElement("div", { className: utils_1.classNames(navigation.prevEl) }) : null;
      },
      renderNextButton: function (_a) {
          var navigation = _a.navigation;
          return navigation ? react_1.default.createElement("div", { className: utils_1.classNames(navigation.nextEl) }) : null;
      },
      renderParallax: function (_a) {
          var parallaxEl = _a.parallaxEl;
          return parallaxEl ? (react_1.default.createElement("div", { className: utils_1.classNames(parallaxEl.el), "data-swiper-parallax": parallaxEl.value })) : null;
      },
      modules: []
  };
  ReactIdSwiperCustom.displayName = 'ReactIdSwiperCustom';
  exports.default = ReactIdSwiperCustom;
  