function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { Component } from "react";
import { Platform, View, Modal, TouchableOpacity, StyleSheet } from "react-native";
import * as ScreenOrientation from "expo-screen-orientation";
import { StatusBarHeight, getCompressed, imageExists } from "../helper";
import { FontAwesome } from "./Icon";
import { SharingTools } from "./SharingTools";
import MediaPlayer from "./MediaPlayer";
class VideoPopup extends Component {
  constructor(props) {
    super(props);
    _defineProperty(this, "UNSAFE_componentWillMount", async () => {
      this.checkCompressed(this.props.uri);
      await ScreenOrientation.lockAsync(Platform.OS === "ios" ? ScreenOrientation.OrientationLock.DEFAULT : ScreenOrientation.OrientationLock.ALL);
    });
    _defineProperty(this, "componentWillUnmount", async () => {
      await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP);
    });
    _defineProperty(this, "checkCompressed", url => {
      const compressedUri = getCompressed(url);
      imageExists(compressedUri).then(compressedExists => {
        this.setState({
          uri: compressedExists ? compressedUri : url
        });
      });
    });
    this.state = {
      uri: "",
      isFullScreen: false
    };
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (this.props.uri === nextProps.uri) return;
    this.checkCompressed(nextProps.uri);
  }
  renderClose() {
    return /*#__PURE__*/React.createElement(TouchableOpacity, {
      style: styles.menuIconContainer,
      onPress: this.props.onClose,
      activeOpacity: 0.6
    }, /*#__PURE__*/React.createElement(FontAwesome, {
      name: "x",
      style: styles.menuIcon
    }));
  }
  renderPlayer() {
    const {
      uri
    } = this.state;
    if (!uri) return null;
    return /*#__PURE__*/React.createElement(View, {
      style: styles.playerContainer
    }, /*#__PURE__*/React.createElement(MediaPlayer, {
      source: uri,
      useVideoPlayer: true,
      autoPlay: true,
      orientationChanged: isFullScreen => this.setState({
        isFullScreen
      })
    }));
  }
  render() {
    const {
      isFullScreen
    } = this.state;
    const {
      visible,
      onClose,
      animationType,
      style
    } = this.props;
    return /*#__PURE__*/React.createElement(Modal, {
      visible: visible,
      animationType: animationType || "fade",
      onRequestClose: onClose,
      style: [styles.container, style],
      supportedOrientations: ["portrait", "landscape"]
    }, this.renderPlayer(), !isFullScreen && this.renderClose(), !isFullScreen && /*#__PURE__*/React.createElement(SharingTools, {
      uri: this.props.uri
    }));
  }
}
const styles = StyleSheet.create({
  container: {
    backgroundColor: "#000"
  },
  menuIconContainer: {
    position: "absolute",
    top: StatusBarHeight(0),
    right: 0,
    width: 55,
    height: 55,
    zIndex: 3
  },
  menuIcon: {
    fontSize: 25,
    padding: 15,
    width: 55,
    textAlign: "center",
    color: "#fff",
    zIndex: 3
  },
  playerContainer: {
    flex: 1,
    backgroundColor: "#000",
    alignItems: "center",
    justifyContent: "center"
  }
});
export { VideoPopup };
//# sourceMappingURL=VideoPopup.js.map