"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 {
    assertInternetReachable
  } = (0, _network.useNetwork)();
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const [hasShown, setHasShown] = (0, _react.useState)(false);
  const showNetworkWarning = (0, _react.useCallback)(() => {
    setHasShown(true);
    _reactNativeToastMessage.default.show({
      type: _BaseToast.ToastType.Error,
      autoHide: true,
      text1: t('NetInfo.NoInternetConnectionTitle')
    });
  }, [t]);
  (0, _react.useEffect)(() => {
    const internetReachable = assertInternetReachable();
    if (internetReachable) {
      _reactNativeToastMessage.default.hide();
    }

    // Strict check for false, null means the network state is not yet known
    if (internetReachable === false && !hasShown) {
      showNetworkWarning();
    }
  }, [showNetworkWarning, assertInternetReachable, hasShown]);
  return null;
};
var _default = exports.default = NetInfo;
//# sourceMappingURL=NetInfo.js.map