"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Lightbox = void 0;

var _react = _interopRequireWildcard(require("react"));

var _reactImageLightbox = _interopRequireDefault(require("react-image-lightbox"));

var _components = require("./components");

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; }

var __jsx = _react["default"].createElement;

// still uses context and self-adding images
// Switch to use lightbox library - no need to reinvent the wheel
var Lightbox = function Lightbox() {
  var context = (0, _components.useGalleryContext)();
  var activeItem = context.activeItem,
      activeIndex = context.activeIndex,
      media = context.media,
      setActiveItem = context.setActiveItem,
      onPrev = context.onPrev,
      onNext = context.onNext;
  (0, _react.useEffect)(function () {
    if (activeItem && (media === null || media === void 0 ? void 0 : media.length) > 0) {
      document.body.style.overflow = 'hidden';
      return function () {
        document.body.style.overflow = 'unset';
      };
    }

    return function () {
      return null;
    };
  }, [activeItem, media === null || media === void 0 ? void 0 : media.length]);

  if (activeItem && (media === null || media === void 0 ? void 0 : media.length) > 0) {
    var _media$activeIndex, _media, _media2;

    var current = (_media$activeIndex = media[activeIndex]) === null || _media$activeIndex === void 0 ? void 0 : _media$activeIndex.src;
    var next = (_media = media[(activeIndex + 1) % media.length]) === null || _media === void 0 ? void 0 : _media.src;
    var prev = (_media2 = media[(activeIndex + media.length - 1) % media.length]) === null || _media2 === void 0 ? void 0 : _media2.src;
    return __jsx(_reactImageLightbox["default"], {
      mainSrc: current // mainSrcThumbnail={current}
      ,
      nextSrc: next // nextSrcThumbnail={next}
      ,
      prevSrc: prev // prevSrcThumbnail={prev}
      ,
      onCloseRequest: function onCloseRequest() {
        return setActiveItem(null);
      },
      onMovePrevRequest: function onMovePrevRequest() {
        return onPrev();
      },
      onMoveNextRequest: function onMoveNextRequest() {
        return onNext();
      }
    });
  }

  return null;
};

exports.Lightbox = Lightbox;
//# sourceMappingURL=Lightbox.js.map