"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.saveConfig = exports.removeOnStateChangeListener = exports.prepare = exports.onStateChangedListener = exports.getCurrentState = exports.getConnectionTimeSecond = exports.getCharonErrorState = exports.disconnect = exports.default = exports.connect = exports.VpnState = exports.STATE_CHANGED_EVENT_NAME = exports.CharonErrorState = void 0;
var _reactNative = require("react-native");
// the generic VPN state for all platforms.
let VpnState; /// the error state from `VpnStateService`.
/// only available for Android device.
exports.VpnState = VpnState;
(function (VpnState) {
  VpnState[VpnState["invalid"] = 0] = "invalid";
  VpnState[VpnState["disconnected"] = 1] = "disconnected";
  VpnState[VpnState["connecting"] = 2] = "connecting";
  VpnState[VpnState["connected"] = 3] = "connected";
  VpnState[VpnState["reasserting"] = 4] = "reasserting";
  VpnState[VpnState["disconnecting"] = 5] = "disconnecting";
})(VpnState || (exports.VpnState = VpnState = {}));
let CharonErrorState;
exports.CharonErrorState = CharonErrorState;
(function (CharonErrorState) {
  CharonErrorState[CharonErrorState["NO_ERROR"] = 0] = "NO_ERROR";
  CharonErrorState[CharonErrorState["AUTH_FAILED"] = 1] = "AUTH_FAILED";
  CharonErrorState[CharonErrorState["PEER_AUTH_FAILED"] = 2] = "PEER_AUTH_FAILED";
  CharonErrorState[CharonErrorState["LOOKUP_FAILED"] = 3] = "LOOKUP_FAILED";
  CharonErrorState[CharonErrorState["UNREACHABLE"] = 4] = "UNREACHABLE";
  CharonErrorState[CharonErrorState["GENERIC_ERROR"] = 5] = "GENERIC_ERROR";
  CharonErrorState[CharonErrorState["PASSWORD_MISSING"] = 6] = "PASSWORD_MISSING";
  CharonErrorState[CharonErrorState["CERTIFICATE_UNAVAILABLE"] = 7] = "CERTIFICATE_UNAVAILABLE";
  CharonErrorState[CharonErrorState["UNDEFINED"] = 8] = "UNDEFINED";
})(CharonErrorState || (exports.CharonErrorState = CharonErrorState = {}));
const stateChanged = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.RNIpSecVpn);

// receive state change from VPN service.
const STATE_CHANGED_EVENT_NAME = 'stateChanged';

// remove change listener
exports.STATE_CHANGED_EVENT_NAME = STATE_CHANGED_EVENT_NAME;
const removeOnStateChangeListener = stateChangedEvent => {
  stateChangedEvent.remove();
};

// set a change listener
exports.removeOnStateChangeListener = removeOnStateChangeListener;
const onStateChangedListener = callback => {
  return stateChanged.addListener(STATE_CHANGED_EVENT_NAME, e => callback(e));
};

// prepare for vpn connection.
//
// android:
//   for first connection it will show a dialog to ask for permission.
//   when your connection was interrupted by another VPN connection,
//   you should prepare again before reconnect.
//   also if activity isn't running yet,
//   the activity can be null and will raise an exception
//   in this case prepare should be called once again when the activity is running.
//
// ios:
//   create a watch for state change
//   does not raise anything
exports.onStateChangedListener = onStateChangedListener;
const prepare = _reactNative.NativeModules.RNIpSecVpn.prepare;

// connect to VPN.
exports.prepare = prepare;
const connect = (name, address, username, password, secret, disapleOnSleep) => {
  if (_reactNative.Platform.OS == 'ios') {
    return _reactNative.NativeModules.RNIpSecVpn.connect(name, address || '', username || '', password || '', secret || '', disapleOnSleep);
  } else {
    return _reactNative.NativeModules.RNIpSecVpn.connect(address || '', username || '', password || '');
  }
};
exports.connect = connect;
const saveConfig = (name, address, username, password, secret) => {
  if (_reactNative.Platform.OS == 'ios') {
    return _reactNative.NativeModules.RNIpSecVpn.saveConfig(name, address || '', username || '', password || '', secret || '');
  } else {
    return _reactNative.NativeModules.RNIpSecVpn.connect(address || '', username || '', password || '');
  }
};

// get current state
exports.saveConfig = saveConfig;
const getCurrentState = _reactNative.NativeModules.RNIpSecVpn.getCurrentState;
exports.getCurrentState = getCurrentState;
const getConnectionTimeSecond = _reactNative.NativeModules.RNIpSecVpn.getConnectionTimeSecond;

// get current error state from `VpnStateService`. (Android only will recieve no error on ios)
// when [VpnState.genericError] is receivedon android, details of error can be
// inspected by [CharonErrorState].
exports.getConnectionTimeSecond = getConnectionTimeSecond;
const getCharonErrorState = _reactNative.NativeModules.RNIpSecVpn.getCharonErrorState;

// disconnect and stop VPN service.
// does not raise any exception
exports.getCharonErrorState = getCharonErrorState;
const disconnect = _reactNative.NativeModules.RNIpSecVpn.disconnect;
exports.disconnect = disconnect;
var _default = _reactNative.NativeModules.RNIpSecVpn;
exports.default = _default;
//# sourceMappingURL=index.js.map