import { initEnv } from '../env/env.mjs';
import { launchCore, GAME_SCHEME_PREFIX_MAP, DEFAULT_WX_JS_SDK } from './helper.mjs';
import '@babel/runtime/helpers/defineProperty';
import '../game/game.mjs';
import '../constant/gid.mjs';
import '../loader/little-loader.mjs';
import '../msdk/msdk.mjs';
import '@babel/runtime/helpers/typeof';
import '../url/url.mjs';

function getMJSchemeParam(_ref) {
  var seriesId = _ref.seriesId,
    gameId = _ref.gameId,
    uin = _ref.uin;
  var schemeParam = "firmMatch=1&seriesid=".concat(seriesId, "&gameid=").concat(gameId, "&uin=").concat(uin);
  return schemeParam;
}
/**
 * 拉起 MJ
 * @param {object} params 拉起参数
 * @param {string} params.seriesId series id
 * @param {string} params.gameId game id
 * @param {string} params.uin uin
 * @param {object} [params.context] 上下文，可传入组件实例 this
 * @param {object} [params.qrCodeLib] qrcode
 * @param {object} [params.dialogHandler] 弹窗 handler
 * @param {object} [params.otherDialogParams] 弹窗的其他参数
 * @param {string} [params.wxJSLink] wx js link
 * @param {object} [params.env] 环境对象
 * @returns Promise<boolean | number>
 *
 * @example
 * ```ts
 * launchMJGameRoom({
 *   seriesId: '12',
 *   gameId: '123',
 *   uin: '222',
 * })
 * ```
 */
function launchMJGameRoom(_ref2) {
  var _ref2$seriesId = _ref2.seriesId,
    seriesId = _ref2$seriesId === void 0 ? '' : _ref2$seriesId,
    _ref2$gameId = _ref2.gameId,
    gameId = _ref2$gameId === void 0 ? '' : _ref2$gameId,
    _ref2$uin = _ref2.uin,
    uin = _ref2$uin === void 0 ? '' : _ref2$uin,
    context = _ref2.context,
    qrCodeLib = _ref2.qrCodeLib,
    dialogHandler = _ref2.dialogHandler,
    otherDialogParams = _ref2.otherDialogParams,
    _ref2$wxJSLink = _ref2.wxJSLink,
    wxJSLink = _ref2$wxJSLink === void 0 ? DEFAULT_WX_JS_SDK : _ref2$wxJSLink,
    _ref2$env = _ref2.env,
    env = _ref2$env === void 0 ? initEnv() : _ref2$env;
  var schemeParam = getMJSchemeParam({
    seriesId: seriesId,
    gameId: gameId,
    uin: uin
  });
  return launchCore({
    launchParams: {
      seriesId: seriesId,
      gameId: gameId,
      uin: uin
    },
    schemeParam: schemeParam,
    context: context,
    qrCodeLib: qrCodeLib,
    dialogHandler: dialogHandler,
    otherDialogParams: otherDialogParams,
    schemePrefix: GAME_SCHEME_PREFIX_MAP.MJ,
    wxJSLink: wxJSLink,
    env: env
  });
}

export { launchMJGameRoom };
