"use strict";

import React, { useMemo } from 'react';
import { Provider } from 'react-redux';
import { KeyboardProvider } from 'react-native-keyboard-controller';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { store } from '../../roomStore';
import { XmppProvider } from '../../context/xmppProvider';
import { MessageNotificationProvider } from '../../context/MessageNotificationContext';
import { ToastProvider } from '../../context/ToastContext';
import LoginWrapper from './LoginWrapper';
import '../../helpers/storeConsole';
import { installPromiseRejectionTracker } from '../../utils/installPromiseRejectionTracker';

// Mount-time, dev-only — wire a global unhandled-promise-rejection
// tracker so any future leak surfaces with a real stack trace in Metro
// logs (bug #4 follow-up). No-op in production.
import { jsx as _jsx } from "react/jsx-runtime";
installPromiseRejectionTracker();
export const ReduxWrapper = /*#__PURE__*/React.memo(({
  ...props
}) => {
  const memoizedConfig = useMemo(() => {
    return props.config;
  }, [props.config]);

  // Host apps that own their keyboard handling (their own
  // KeyboardProvider + KeyboardAvoidingView around <Chat>) set
  // `disableKeyboardAvoidingView` — drop the built-in KeyboardProvider
  // here too so there aren't two nested providers (the second is part of
  // the Android keyboard flicker in bug #6; ChatRoom drops the matching
  // KeyboardAvoidingView under the same flag).
  const ownKeyboardHandling = !memoizedConfig?.disableKeyboardAvoidingView;
  const tree = /*#__PURE__*/_jsx(XmppProvider, {
    config: memoizedConfig,
    isVisible: props.isVisible,
    children: /*#__PURE__*/_jsx(ToastProvider, {
      children: /*#__PURE__*/_jsx(MessageNotificationProvider, {
        config: memoizedConfig,
        children: /*#__PURE__*/_jsx(LoginWrapper, {
          config: memoizedConfig,
          ...props
        })
      })
    })
  });
  return /*#__PURE__*/_jsx(Provider, {
    store: store,
    children: /*#__PURE__*/_jsx(SafeAreaProvider, {
      children: ownKeyboardHandling ? /*#__PURE__*/_jsx(KeyboardProvider, {
        children: tree
      }) : tree
    })
  });
});
//# sourceMappingURL=ReduxWrapper.js.map