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; }
import { NativeModules, Platform } from 'react-native';
import { LINKING_ERROR } from './error';
import { AuthsignalEmail } from './email';
import { AuthsignalPasskey } from './passkey';
import { AuthsignalPush } from './push';
import { AuthsignalSms } from './sms';
import { AuthsignalTotp } from './totp';
import { AuthsignalDevice } from './device';
import { AuthsignalWhatsapp } from './whatsapp';
export * from './types';
export { ErrorCode } from './error';
const AuthsignalModule = NativeModules.AuthsignalModule ? NativeModules.AuthsignalModule : new Proxy({}, {
  get() {
    throw new Error(LINKING_ERROR);
  }
});
export class Authsignal {
  constructor(_ref) {
    let {
      tenantID,
      baseURL = 'https://api.authsignal.com/v1',
      deviceID,
      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);
    _defineProperty(this, "whatsapp", void 0);
    this.tenantID = tenantID;
    this.baseURL = baseURL;
    this.enableLogging = enableLogging;
    this.passkey = new AuthsignalPasskey({
      tenantID,
      baseURL,
      deviceID,
      enableLogging
    });
    this.email = new AuthsignalEmail({
      tenantID,
      baseURL,
      enableLogging
    });
    this.push = new AuthsignalPush({
      tenantID,
      baseURL,
      enableLogging
    });
    this.device = new AuthsignalDevice({
      tenantID,
      baseURL,
      enableLogging
    });
    this.sms = new AuthsignalSms({
      tenantID,
      baseURL,
      enableLogging
    });
    this.totp = new AuthsignalTotp({
      tenantID,
      baseURL,
      enableLogging
    });
    this.whatsapp = new AuthsignalWhatsapp({
      tenantID,
      baseURL,
      enableLogging
    });
  }
  async setToken(token) {
    await AuthsignalModule.setToken(token);
  }
  async launch(url) {
    return await launch(url);
  }
}
export function launch(url) {
  if (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