'use strict'
var _extends =
  Object.assign ||
  function(a) {
    for (var b, c = 1; c < arguments.length; c++)
      for (var d in ((b = arguments[c]), b))
        Object.prototype.hasOwnProperty.call(b, d) && (a[d] = b[d])
    return a
  }
!(function(require, directRequire) {
  const a = require('./233d77ecf0781f44985f684f70e316d0.js'),
    b = require('./89ba85d67a88f7636d657c22b5d3e038.js'),
    c = require('./df6d0ff021a69fb541c733de4dbba0fe.js'),
    d = require('./9c906d27ca74e18d0deaaa231e71fdfa.js'),
    e = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    f = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    g = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    h = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    i = require('./common/locales/index.js'),
    j = require('./logger.js'),
    {
      NOT_LOGIN: k,
      INVALID_TOKEN: l,
      INVALID_LOGIN: m,
      DEV_NEED_RELOGIN: n,
      DEV_INVALID_SIGNATURE: o,
      DEV_EXPIRED_SIGNATURE: p
    } = c,
    q = 'darwin' === process.platform ? 'darwin' : 'win',
    r = global.appVersion.replace(/\./g, ''),
    s = a => {
      let { needAppID: b, needRandom: c, needSystemInfo: d } = a
      delete a.needAppID, delete a.needRandom
      let e = (a.url || '').split('?'),
        g = e[0],
        h = []
      return (
        -1 !== c && h.push(`_r=${Math.random()}`),
        1 === b && h.push(`${f.formatAppIDQuery()}`),
        -1 !== d && h.push(`os=${q}&clientversion=${r}`),
        e[1] && h.push(e[1]),
        (a.url = `${g}?${h.join('&')}`),
        a
      )
    },
    t = a => {
      return a === k || a === l || a === n || a === p || a === o
        ? (e.dispatch(d.loginExpired()), !0)
        : void 0
    },
    u = b => {
      return new Promise((c, d) => {
        a(b, (a, b, e) => {
          a && d(a), c({ resp: b, body: e })
        })
      })
    },
    v = async function(a, c = !0) {
      let f = _extends({}, a),
        {
          needToken: h,
          needParse: k,
          needCheckErrCode: l,
          needCheckStatusCode: n,
          forceLogin: o
        } = f
      if (
        (delete f.needToken,
        delete f.needParse,
        delete f.needCheckErrCode,
        delete f.needCheckStatusCode,
        1 === h)
      )
        try {
          f = await b.makeRequestOptionsWithLoginState(f)
        } catch (a) {
          if (-1 != o) throw (t(a), i.config.CGI_ERR_NEED_RELOGIN)
          else;
        }
      f = s(f)
      try {
        let { resp: p, body: q } = await u(f, !0)
        if (-1 !== n) {
          const a = p.statusCode
          if (200 != a && 206 != a)
            throw (j.error(`${f.url} ${a}`), i.config.NETWORK_ERROR.format(a))
        }
        if (-1 === k) return { resp: p, body: q }
        let r = JSON.parse(q)
        if (-1 !== l) {
          let f = r.baseresponse || {},
            i = f.errcode
          if (void 0 !== i && 0 !== i) {
            if (1 === h && -1 != o && (t(i), i == m)) {
              if (c) {
                let c = !1
                try {
                  await b.requestRefreshTicket(), (c = !0)
                } catch (a) {
                  j.error(`refresh ticket catch error ${a}`), (c = !1)
                }
                if (c)
                  return j.info(`request after refresh ticket`), await v(a, !1)
              }
              e.dispatch(d.loginExpired())
            }
            const k = g.parseCgiErrorCode(i, f.errmsg),
              l = new Error(k)
            throw ((l.errcode = i), l)
          }
        }
        return { resp: p, body: r }
      } catch (a) {
        throw (j.error(`${f.url} ${a}`), a)
      }
    }
  module.exports = v
})(require('lazyload'), require)
