"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _ImageDefaultHeader = _interopRequireDefault(require("./components/ImageDefaultHeader"));
var _StatusBarManager = _interopRequireDefault(require("./components/StatusBarManager"));
var _useAnimatedComponents = _interopRequireDefault(require("./hooks/useAnimatedComponents"));
var _useImageIndexChange = _interopRequireDefault(require("./hooks/useImageIndexChange"));
var _useRequestClose = _interopRequireDefault(require("./hooks/useRequestClose"));
var _reactNativeVideo = _interopRequireDefault(require("react-native-video"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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); } /**
                                                                                                                                                                                                                                                                                                                                                     * Copyright (c) JOB TODAY S.A. and its affiliates.
                                                                                                                                                                                                                                                                                                                                                     *
                                                                                                                                                                                                                                                                                                                                                     * This source code is licensed under the MIT license found in the
                                                                                                                                                                                                                                                                                                                                                     * LICENSE file in the root directory of this source tree.
                                                                                                                                                                                                                                                                                                                                                     *
                                                                                                                                                                                                                                                                                                                                                     */ // @ts-nocheck
const DEFAULT_ANIMATION_TYPE = 'fade';
const DEFAULT_BG_COLOR = '#000';
const DEFAULT_DELAY_LONG_PRESS = 800;
const SCREEN = _reactNative.Dimensions.get('screen');
const SCREEN_WIDTH = SCREEN.width;
function ImageViewing(_ref) {
  let {
    images,
    keyExtractor,
    imageIndex,
    visible,
    onRequestClose,
    onLongPress = () => {},
    onImageIndexChange,
    animationType = DEFAULT_ANIMATION_TYPE,
    backgroundColor = DEFAULT_BG_COLOR,
    presentationStyle,
    swipeToCloseEnabled,
    doubleTapToZoomEnabled,
    delayLongPress = DEFAULT_DELAY_LONG_PRESS,
    HeaderComponent,
    FooterComponent,
    source
  } = _ref;
  const imageList = (0, _react.useRef)(null);
  const [opacity, onRequestCloseEnhanced] = (0, _useRequestClose.default)(onRequestClose);
  const [currentImageIndex, onScroll] = (0, _useImageIndexChange.default)(imageIndex, SCREEN);
  const [headerTransform, footerTransform, toggleBarsVisible] = (0, _useAnimatedComponents.default)();
  const videoRef = (0, _react.useRef)();
  const [isLoading, setIsLoading] = (0, _react.useState)(true);
  (0, _react.useEffect)(() => {
    if (onImageIndexChange) {
      onImageIndexChange(currentImageIndex);
    }
  }, [currentImageIndex]);
  (0, _react.useEffect)(() => {
    return () => {
      try {} catch (e) {}
    };
  }, []);
  const onZoom = (0, _react.useCallback)(isScaled => {
    var _imageList$current;
    // @ts-ignore
    imageList === null || imageList === void 0 ? void 0 : (_imageList$current = imageList.current) === null || _imageList$current === void 0 ? void 0 : _imageList$current.setNativeProps({
      scrollEnabled: !isScaled
    });
    toggleBarsVisible(!isScaled);
  }, [imageList]);
  if (!visible) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_reactNative.Modal, {
    transparent: presentationStyle === 'overFullScreen',
    visible: visible,
    presentationStyle: presentationStyle,
    animationType: animationType,
    onRequestClose: onRequestCloseEnhanced,
    supportedOrientations: ['portrait'],
    hardwareAccelerated: true
  }, /*#__PURE__*/_react.default.createElement(_StatusBarManager.default, {
    presentationStyle: presentationStyle
  }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.container, {
      opacity,
      backgroundColor
    }]
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: [styles.header, {
      transform: headerTransform
    }]
  }, typeof HeaderComponent !== 'undefined' ? /*#__PURE__*/_react.default.createElement(HeaderComponent, {
    imageIndex: currentImageIndex
  }) : /*#__PURE__*/_react.default.createElement(_ImageDefaultHeader.default, {
    onRequestClose: onRequestCloseEnhanced
  })), /*#__PURE__*/_react.default.createElement(_reactNativeVideo.default, {
    style: {
      flex: 1
    },
    resizeMode: "contain",
    ref: videoRef,
    source: source,
    controls: true,
    isPaused: true,
    onLoad: status => {
      setIsLoading(false);
    }
  }), isLoading && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      width: '100%',
      height: '100%',
      alignItems: 'center',
      justifyContent: 'center',
      position: 'absolute'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.ActivityIndicator, {
    color: 'white',
    size: 'large'
  }))));
}
const styles = _reactNative.StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#000'
  },
  header: {
    position: 'absolute',
    width: '100%',
    zIndex: 1,
    top: 0
  },
  footer: {
    position: 'absolute',
    width: '100%',
    zIndex: 1,
    bottom: 0
  }
});
const EnhancedImageViewing = props => /*#__PURE__*/_react.default.createElement(ImageViewing, _extends({
  key: props.imageIndex
}, props));
var _default = EnhancedImageViewing;
exports.default = _default;
//# sourceMappingURL=ImageViewing.js.map