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
import React, { useCallback, useRef, useEffect, useState } from 'react';
import { Animated, Dimensions, StyleSheet, View, Modal, ActivityIndicator } from 'react-native';
import ImageDefaultHeader from './components/ImageDefaultHeader';
import StatusBarManager from './components/StatusBarManager';
import useAnimatedComponents from './hooks/useAnimatedComponents';
import useImageIndexChange from './hooks/useImageIndexChange';
import useRequestClose from './hooks/useRequestClose';
import Video from 'react-native-video';
const DEFAULT_ANIMATION_TYPE = 'fade';
const DEFAULT_BG_COLOR = '#000';
const DEFAULT_DELAY_LONG_PRESS = 800;
const SCREEN = 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 = useRef(null);
  const [opacity, onRequestCloseEnhanced] = useRequestClose(onRequestClose);
  const [currentImageIndex, onScroll] = useImageIndexChange(imageIndex, SCREEN);
  const [headerTransform, footerTransform, toggleBarsVisible] = useAnimatedComponents();
  const videoRef = useRef();
  const [isLoading, setIsLoading] = useState(true);
  useEffect(() => {
    if (onImageIndexChange) {
      onImageIndexChange(currentImageIndex);
    }
  }, [currentImageIndex]);
  useEffect(() => {
    return () => {
      try {} catch (e) {}
    };
  }, []);
  const onZoom = 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.createElement(Modal, {
    transparent: presentationStyle === 'overFullScreen',
    visible: visible,
    presentationStyle: presentationStyle,
    animationType: animationType,
    onRequestClose: onRequestCloseEnhanced,
    supportedOrientations: ['portrait'],
    hardwareAccelerated: true
  }, /*#__PURE__*/React.createElement(StatusBarManager, {
    presentationStyle: presentationStyle
  }), /*#__PURE__*/React.createElement(View, {
    style: [styles.container, {
      opacity,
      backgroundColor
    }]
  }, /*#__PURE__*/React.createElement(Animated.View, {
    style: [styles.header, {
      transform: headerTransform
    }]
  }, typeof HeaderComponent !== 'undefined' ? /*#__PURE__*/React.createElement(HeaderComponent, {
    imageIndex: currentImageIndex
  }) : /*#__PURE__*/React.createElement(ImageDefaultHeader, {
    onRequestClose: onRequestCloseEnhanced
  })), /*#__PURE__*/React.createElement(Video, {
    style: {
      flex: 1
    },
    resizeMode: "contain",
    ref: videoRef,
    source: source,
    controls: true,
    isPaused: true,
    onLoad: status => {
      console.log(status);
      setIsLoading(false);
    }
  }), isLoading && /*#__PURE__*/React.createElement(View, {
    style: {
      width: '100%',
      height: '100%',
      alignItems: 'center',
      justifyContent: 'center',
      position: 'absolute'
    }
  }, /*#__PURE__*/React.createElement(ActivityIndicator, {
    color: 'white',
    size: 'large'
  }))));
}
const styles = 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.createElement(ImageViewing, _extends({
  key: props.imageIndex
}, props));
export default EnhancedImageViewing;
//# sourceMappingURL=ImageViewing.js.map