import { OverlayContainer } from '@react-native-aria/overlays';
import React from 'react';
import { Platform } from 'react-native';
import { Modal } from 'react-native';
import { useKeyboardDismissable } from '../../../hooks';
import { ExitAnimationContext } from './ExitAnimationContext';
export function Overlay({
  children,
  isOpen,
  useRNModalOnAndroid = false,
  isKeyboardDismissable = true,
  animationPreset = 'fade',
  onRequestClose
}) {
  const [exited, setExited] = React.useState(!isOpen);
  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 (Platform.OS === 'android' && useRNModalOnAndroid) {
    return /*#__PURE__*/React.createElement(ExitAnimationContext.Provider, {
      value: {
        exited,
        setExited
      }
    }, /*#__PURE__*/React.createElement(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.createElement(OverlayContainer, {
      style: {
        display: display
      }
    }, /*#__PURE__*/React.createElement(ExitAnimationContext.Provider, {
      value: {
        exited,
        setExited
      }
    }, children))
  );
}
//# sourceMappingURL=Overlay.js.map