"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactI18next = require("react-i18next");
var _reactNativeToastMessage = _interopRequireDefault(require("react-native-toast-message"));
var _network = require("../../contexts/network");
var _BaseToast = require("../../components/toast/BaseToast");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const NetInfo = () => {
  const {
    silentAssertConnectedNetwork,
    assertNetworkReachable
  } = (0, _network.useNetwork)();
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const [hasShown, setHasShown] = (0, _react.useState)(false);
  const isConnected = silentAssertConnectedNetwork();
  (0, _react.useEffect)(() => {
    // Network is connected
    if (isConnected) {
      // Assert that internet is available
      assertNetworkReachable().then(status => {
        // Connected to a network, reset toast
        setHasShown(false);
        if (status) {
          return;
        }

        // User is connected to a network but has no internet, display toast
        _reactNativeToastMessage.default.show({
          type: _BaseToast.ToastType.Error,
          autoHide: true,
          text1: t('NetInfo.NoInternetConnectionTitle')
        });
      });
      return;
    }

    // Only show the toast if the user hasn't seen it already
    if (!hasShown) {
      setHasShown(true);
      _reactNativeToastMessage.default.show({
        type: _BaseToast.ToastType.Error,
        autoHide: true,
        text1: t('NetInfo.NoInternetConnectionTitle')
      });
    }
  }, [isConnected, assertNetworkReachable, t, hasShown]);
  return null;
};
var _default = exports.default = NetInfo;
//# sourceMappingURL=NetInfo.js.map