"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _reactNativeEventListeners = require("react-native-event-listeners");
var _reactNativeWebview = _interopRequireDefault(require("react-native-webview"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const MainWebView = props => {
  const {
    url,
    source,
    loading,
    isError,
    webviewRef,
    handleMessage,
    runBeforeFirst,
    platform,
    setCanGoBack
  } = props; // Get the URL and other parameters from the route

  return /*#__PURE__*/_react.default.createElement(_reactNative.SafeAreaView, {
    style: {
      flex: 1
    }
  }, (isError || loading) && /*#__PURE__*/_react.default.createElement(LoadingIndicator, null), source && !isError && !loading ? /*#__PURE__*/_react.default.createElement(_reactNativeWebview.default, _extends({
    ref: webviewRef,
    source: {
      uri: source,
      headers: {
        platform: platform
      }
    },
    onMessage: handleMessage
  }, runBeforeFirst && {
    injectedJavaScriptBeforeContentLoaded: runBeforeFirst
  }, {
    javaScriptEnabled: true,
    onLoadProgress: event => setCanGoBack(event.nativeEvent.canGoBack),
    onError: errorMessage => {
      _reactNativeEventListeners.EventRegister.emitEvent('mytatva-event', {
        message: 'web-view-error',
        errorMessage: errorMessage
      });
    }
  })) : null);
};
var _default = exports.default = MainWebView;
const LoadingIndicator = () => {
  return /*#__PURE__*/_react.default.createElement(_reactNative.ActivityIndicator, {
    color: "#000",
    size: "large"
    // eslint-disable-next-line react-native/no-inline-styles
    ,
    style: {
      flex: 1,
      zIndex: 100,
      position: 'absolute',
      backgroundColor: '#fff',
      opacity: 0.4,
      width: '100%',
      height: '100%',
      justifyContent: 'center',
      alignItems: 'center'
    }
  });
};
//# sourceMappingURL=MainWebView.js.map