/**
 * 登录bilibili
 * @param {{
 *   inBiliApp: boolean;
 *   isSupport: (method: string) => Promise<boolean>;
 *   biliBridge: { callNative: options => any };
 * }} jsb js-bridge对象
 * @param {string|undefined} callbackUrl
 *
 * @example
 * import * as jsb from '@bilibili/js-bridge';
 *
 * goToLogin(jsb);
 */
function goToLogin(jsb, callbackUrl) {
  if (!callbackUrl) callbackUrl = window.location.href;

  var _ref = jsb || {},
      inBiliApp = _ref.inBiliApp,
      biliBridge = _ref.biliBridge;

  if (!biliBridge) {
    console.error('JSB对象不正确！');
    return null;
  }

  if (inBiliApp) {
    biliBridge.callNative({
      method: 'auth.login',
      data: {
        type: 'default',
        callbackUrl: callbackUrl
      }
    });
  } else {
    window.location.href = "https://passport.bilibili.com/login?gourl=".concat(encodeURIComponent(callbackUrl));
  }
}

export default goToLogin;
