"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
const Popup = ({
  open,
  setOpen,
  position,
  style,
  children
}) => {
  const [visible, setVisible] = (0, _react.useState)(true);
  const {
    width,
    height
  } = _reactNative.Dimensions.get('screen');
  const styles = _reactNative.StyleSheet.create({
    outer: {
      position: 'absolute',
      top: 0,
      left: 0,
      width,
      height
    },
    container: {
      position: 'absolute',
      shadowColor: '#000',
      shadowOffset: {
        width: 0,
        height: 6
      },
      shadowOpacity: 0.16,
      shadowRadius: 16,
      elevation: 8,
      // for android
      ...position
    }
  });

  // Animated value for opacity
  const opacity = (0, _react.useState)(new _reactNative.Animated.Value(0))[0];
  const translateY = (0, _react.useState)(new _reactNative.Animated.Value(-10))[0]; // Initial position off-screen

  // Function to show the popup
  const showPopup = (0, _react.useCallback)(() => {
    setVisible(true);
    // Animate both opacity and translateY
    _reactNative.Animated.parallel([_reactNative.Animated.timing(opacity, {
      toValue: 1,
      duration: 300,
      useNativeDriver: true
    }), _reactNative.Animated.timing(translateY, {
      toValue: 0,
      // Slide to original position
      duration: 300,
      useNativeDriver: true
    })]).start();
  }, [opacity, translateY]);
  const hidePopup = (0, _react.useCallback)(() => {
    // Animate both opacity and translateY
    _reactNative.Animated.parallel([_reactNative.Animated.timing(opacity, {
      toValue: 0,
      duration: 150,
      useNativeDriver: true
    }), _reactNative.Animated.timing(translateY, {
      toValue: -10,
      // Slide upwards
      duration: 150,
      useNativeDriver: true
    })]).start(() => setVisible(false)); // Hide the popup after the animation
  }, [opacity, translateY]);
  (0, _react.useEffect)(() => {
    if (open) {
      showPopup();
    } else hidePopup();
  }, [open, showPopup, hidePopup]);
  if (!visible) return null;
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_reactNative.Pressable, {
    style: styles.outer,
    onPress: () => setOpen(false)
  }), /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
    style: [styles.container, {
      opacity,
      transform: [{
        translateY
      }]
    }, style]
  }, children));
};
var _default = exports.default = Popup;
//# sourceMappingURL=PopupMenu.js.map