var e = require("../@babel/runtime/helpers/slicedToArray"),
  n = require("../common/vendor.js"),
  t = require("./useState.js"),
  o = require("../service/index.js"),
  r = require("../utils/util.js");
exports.onMounted = function (i) {
  var u = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1];
  n.onLoad(function (a) {
    var s = t.useState().setChannelName;
    n.index.hideHomeButton(),
      a &&
        a.channelName &&
        !t.useState().channelName.value &&
        s({ channelName: a.channelName });
    var c = new Date().getTime();
    u && r.showLoading(),
      (function () {
        var r = t.useState(),
          i = r.setUserData,
          u = r.setConfig,
          a = n.index.getStorageSync("token"),
          s = n.index.getStorageSync("openId"),
          c = t.useState().userId.value,
          d = t.useState().userInfo.value,
          f = t.useState().config.value,
          l = function () {
            return Promise.resolve({
              token: a,
              openId: s,
              userId: c,
              userInfo: d,
            });
          },
          g = function () {
            return Promise.resolve({ config: f });
          };
        return (
          a || s
            ? c ||
              (l = function () {
                return o.getUserInfo();
              })
            : (l = function () {
                return n.index
                  .login({ provider: "weixin" })
                  .then(function (e) {
                    var n = e.code;
                    return o.loginForMpWeixin({ code: n });
                  })
                  .then(function (e) {
                    return (
                      n.index.setStorageSync("token", e.token),
                      n.index.setStorageSync("openId", e.openId),
                      o.getUserInfo()
                    );
                  });
              }),
          f ||
            (g = function () {
              return o.getConfig();
            }),
          Promise.all([l(), g()]).then(function (n) {
            var t = e(n, 2),
              o = t[0],
              r = t[1];
            i({
              token: o.token,
              openId: o.openId,
              userId: o.userId,
              userInfo: o.userInfo,
            }),
              u({ config: r.config });
          })
        );
      })().then(function () {
        i(
          n._.assign(
            a.params ? JSON.parse(decodeURIComponent(a.params)) : null,
            { loadingTime: new Date().getTime() - c }
          )
        );
      });
  });
};
