"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var _exportNames = {
  Authsignal: true,
  launch: true,
  ErrorCode: true
};
exports.Authsignal = void 0;
Object.defineProperty(exports, "ErrorCode", {
  enumerable: true,
  get: function () {
    return _error.ErrorCode;
  }
});
exports.launch = launch;
var _reactNative = require("react-native");
var _error = require("./error");
var _email = require("./email");
var _passkey = require("./passkey");
var _push = require("./push");
var _sms = require("./sms");
var _totp = require("./totp");
var _device = require("./device");
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _types[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _types[key];
    }
  });
});
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const AuthsignalModule = _reactNative.NativeModules.AuthsignalModule ? _reactNative.NativeModules.AuthsignalModule : new Proxy({}, {
  get() {
    throw new Error(_error.LINKING_ERROR);
  }
});
class Authsignal {
  constructor(_ref) {
    let {
      tenantID,
      baseURL = 'https://api.authsignal.com/v1',
      enableLogging = __DEV__
    } = _ref;
    _defineProperty(this, "tenantID", void 0);
    _defineProperty(this, "baseURL", void 0);
    _defineProperty(this, "enableLogging", void 0);
    _defineProperty(this, "email", void 0);
    _defineProperty(this, "passkey", void 0);
    _defineProperty(this, "push", void 0);
    _defineProperty(this, "device", void 0);
    _defineProperty(this, "sms", void 0);
    _defineProperty(this, "totp", void 0);
    this.tenantID = tenantID;
    this.baseURL = baseURL;
    this.enableLogging = enableLogging;
    this.email = new _email.AuthsignalEmail({
      tenantID,
      baseURL,
      enableLogging
    });
    this.passkey = new _passkey.AuthsignalPasskey({
      tenantID,
      baseURL,
      enableLogging
    });
    this.push = new _push.AuthsignalPush({
      tenantID,
      baseURL,
      enableLogging
    });
    this.device = new _device.AuthsignalDevice({
      tenantID,
      baseURL,
      enableLogging
    });
    this.sms = new _sms.AuthsignalSms({
      tenantID,
      baseURL,
      enableLogging
    });
    this.totp = new _totp.AuthsignalTotp({
      tenantID,
      baseURL,
      enableLogging
    });
  }
  async setToken(token) {
    await AuthsignalModule.setToken(token);
  }
  async launch(url) {
    return await launch(url);
  }
}
exports.Authsignal = Authsignal;
function launch(url) {
  if (_reactNative.Platform.OS === 'ios') {
    return AuthsignalModule.launch(url);
  } else {
    return new Promise((resolve, reject) => {
      const callback = (error, token) => {
        if (token) {
          resolve(token);
        } else if (error) {
          if (error.error === 'user_cancelled') {
            resolve(null);
          } else {
            reject(error);
          }
        } else {
          reject('Unexpected error');
        }
      };
      AuthsignalModule.launch(url, callback);
    });
  }
}
//# sourceMappingURL=index.js.map