"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Overlay = Overlay;

var _overlays = require("@react-native-aria/overlays");

var _react = _interopRequireDefault(require("react"));

var _reactNative = require("react-native");

var _hooks = require("../../../hooks");

var _ExitAnimationContext = require("./ExitAnimationContext");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function Overlay({
  children,
  isOpen,
  useRNModalOnAndroid = false,
  isKeyboardDismissable = true,
  animationPreset = 'fade',
  onRequestClose
}) {
  const [exited, setExited] = _react.default.useState(!isOpen);

  (0, _hooks.useKeyboardDismissable)({
    enabled: isOpen && isKeyboardDismissable,
    callback: onRequestClose ? onRequestClose : () => {}
  }); // if (exited && !isOpen) {
  //   return null;
  // }
  // Android handles multiple Modal in RN and is better for accessibility as it shifts accessibility focus on mount, however it may not needed in case of tooltips, toast where one doesn't need to shift accessibility focus
  //TODO: fix-animation

  let display = exited && !isOpen ? 'none' : 'contents';

  if (animationPreset === 'slide') {
    display = 'contents';
  }

  if (_reactNative.Platform.OS === 'android' && useRNModalOnAndroid) {
    return /*#__PURE__*/_react.default.createElement(_ExitAnimationContext.ExitAnimationContext.Provider, {
      value: {
        exited,
        setExited
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Modal, {
      transparent: true,
      visible: true,
      onRequestClose: onRequestClose
    }, children));
  } // Since OverlayContainer mounts children in NativeBaseProvider  using Context, we need to pass the context by wrapping children


  return (
    /*#__PURE__*/
    //@ts-ignore
    _react.default.createElement(_overlays.OverlayContainer, {
      style: {
        display: display
      }
    }, /*#__PURE__*/_react.default.createElement(_ExitAnimationContext.ExitAnimationContext.Provider, {
      value: {
        exited,
        setExited
      }
    }, children))
  );
}
//# sourceMappingURL=Overlay.js.map