var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AnimatedGalleryVideo = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireDefault(require("react-native-reanimated"));
var _native = require("../../../native");
var _Spinner = require("../../UIComponents/Spinner");
var _useAnimatedGalleryStyle = require("../hooks/useAnimatedGalleryStyle");
var _jsxRuntime = require("react/jsx-runtime");
var _this = this,
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx";
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var oneEighth = 1 / 8;
var styles = _reactNative.StyleSheet.create({
  activityIndicator: {
    alignSelf: 'center'
  },
  videoPlayer: {
    height: '100%',
    width: '100%'
  }
});
var AnimatedGalleryVideo = exports.AnimatedGalleryVideo = _react["default"].memo(function (props) {
  var _useState = (0, _react.useState)(1),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    opacity = _useState2[0],
    setOpacity = _useState2[1];
  var attachmentId = props.attachmentId,
    handleEnd = props.handleEnd,
    handleLoad = props.handleLoad,
    handleProgress = props.handleProgress,
    index = props.index,
    offsetScale = props.offsetScale,
    paused = props.paused,
    previous = props.previous,
    repeat = props.repeat,
    scale = props.scale,
    screenHeight = props.screenHeight,
    selected = props.selected,
    shouldRender = props.shouldRender,
    source = props.source,
    style = props.style,
    translateX = props.translateX,
    translateY = props.translateY,
    videoRef = props.videoRef;
  var onLoadStart = function onLoadStart() {
    setOpacity(1);
  };
  var onLoad = function onLoad(payload) {
    setOpacity(0);
    handleLoad(attachmentId, payload.duration * 1000);
  };
  var onEnd = function onEnd() {
    handleEnd();
  };
  var onProgress = function onProgress(data) {
    handleProgress(attachmentId, data.currentTime / data.seekableDuration);
  };
  var onBuffer = function onBuffer(_ref) {
    var isBuffering = _ref.isBuffering;
    if (isBuffering) {
      setOpacity(1);
    } else {
      setOpacity(0);
    }
  };
  var animatedStyles = (0, _useAnimatedGalleryStyle.useAnimatedGalleryStyle)({
    index: index,
    offsetScale: offsetScale,
    previous: previous,
    scale: scale,
    screenHeight: screenHeight,
    selected: selected,
    translateX: translateX,
    translateY: translateY
  });
  if (!shouldRender) {
    return (0, _jsxRuntime.jsx)(_reactNative.View, {
      accessibilityLabel: "Empty View Image Gallery",
      style: [style, {
        transform: [{
          scale: oneEighth
        }]
      }]
    });
  }
  return (0, _jsxRuntime.jsxs)(_reactNativeReanimated["default"].View, {
    accessibilityLabel: "Image Gallery Video",
    style: [].concat((0, _toConsumableArray2["default"])(animatedStyles), [style]),
    children: [(0, _native.isVideoPlayerAvailable)() && _native.NativeHandlers.Video ? (0, _jsxRuntime.jsx)(_native.NativeHandlers.Video, {
      onBuffer: onBuffer,
      onEnd: onEnd,
      onLoad: onLoad,
      onLoadStart: onLoadStart,
      onProgress: onProgress,
      paused: paused,
      repeat: repeat,
      resizeMode: "contain",
      style: style,
      testID: "video-player",
      uri: source.uri,
      videoRef: videoRef
    }) : null, (0, _jsxRuntime.jsx)(_reactNativeReanimated["default"].View, {
      accessibilityLabel: "Spinner",
      style: [styles.activityIndicator, {
        opacity: opacity,
        transform: [{
          scaleX: -1
        }, {
          translateY: -screenHeight * 4
        }, {
          scale: 1 / oneEighth
        }]
      }],
      children: (0, _jsxRuntime.jsx)(_Spinner.Spinner, {
        height: 40,
        width: 40
      })
    })]
  });
}, function (prevProps, nextProps) {
  if (prevProps.paused === nextProps.paused && prevProps.repeat === nextProps.repeat && prevProps.shouldRender === nextProps.shouldRender && prevProps.source.uri === nextProps.source.uri && prevProps.screenHeight === nextProps.screenHeight && prevProps.selected === nextProps.selected && prevProps.previous === nextProps.previous && prevProps.index === nextProps.index) {
    return true;
  }
  return false;
});
AnimatedGalleryVideo.displayName = 'AnimatedGalleryVideo';
//# sourceMappingURL=AnimatedGalleryVideo.js.map