import { initEnv } from '../env/env.mjs';
import { LAUNCH_GP_SOURCE_MAP, getGPSchemeParam, launchCore, DEFAULT_WX_JS_SDK, GAME_SCHEME_PREFIX_MAP } 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';

/**
 * 拉起 GP
 * @param {object} params 拉起参数
 * @param {string} params.roomId 房间 Id
 * @param {string} params.roomPwd 房间 Pwd
 * @param {string} params.source 来源
 * @param {string} [params.wxJSLink] wx js link
 * @param {object} [params.env] 环境对象
 * @param {object} [params.useGPHelperSchemePrefix] 是否使用特殊 scheme
 * @param {object} [params.justLaunchGame] 是否仅拉起 app，不进入房间
 * @returns Promise<boolean | number>
 *
 * @example
 * ```ts
 * launchGPGameRoom({
 *   roomId: '12',
 *   roomPwd: '123'
 * })
 * ```
 */
function launchGPGameRoom(_ref) {
  var _ref$roomId = _ref.roomId,
    roomId = _ref$roomId === void 0 ? '' : _ref$roomId,
    _ref$roomPwd = _ref.roomPwd,
    roomPwd = _ref$roomPwd === void 0 ? '' : _ref$roomPwd,
    _ref$source = _ref.source,
    source = _ref$source === void 0 ? LAUNCH_GP_SOURCE_MAP.NORMAL : _ref$source,
    _ref$wxJSLink = _ref.wxJSLink,
    wxJSLink = _ref$wxJSLink === void 0 ? DEFAULT_WX_JS_SDK : _ref$wxJSLink,
    _ref$env = _ref.env,
    env = _ref$env === void 0 ? initEnv() : _ref$env,
    _ref$useGPHelperSchem = _ref.useGPHelperSchemePrefix,
    useGPHelperSchemePrefix = _ref$useGPHelperSchem === void 0 ? false : _ref$useGPHelperSchem,
    _ref$useTrialSchemePr = _ref.useTrialSchemePrefix,
    useTrialSchemePrefix = _ref$useTrialSchemePr === void 0 ? false : _ref$useTrialSchemePr,
    _ref$justLaunchGame = _ref.justLaunchGame,
    justLaunchGame = _ref$justLaunchGame === void 0 ? false : _ref$justLaunchGame;
  var schemeParam = getGPSchemeParam(roomId, roomPwd, {
    source: source
  });
  var getScheme = function getScheme() {
    if (useTrialSchemePrefix) {
      return GAME_SCHEME_PREFIX_MAP.GP_TRIAL;
    }
    if (useGPHelperSchemePrefix) {
      return GAME_SCHEME_PREFIX_MAP.GP_IN_HELPER;
    }
    return GAME_SCHEME_PREFIX_MAP.GP;
  };
  return launchCore({
    launchParams: {
      roomId: roomId,
      roomPwd: roomPwd
    },
    schemeParam: justLaunchGame ? '' : schemeParam,
    schemePrefix: getScheme(),
    wxJSLink: wxJSLink,
    env: env
  });
}

export { launchGPGameRoom };
