'use strict'
!(function(require, directRequire) {
  const a = require('fs'),
    b = require('path'),
    c = require('rmdir'),
    d = require('zlib'),
    e = require('./logger.js'),
    f = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    g = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    h = require('./1fcc6bd55b687d154a4247e57fe3011d.js'),
    i = require('./db2217eb4cff896bdcbc50abe005058f.js'),
    j = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    k = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    l = require('./92320c1386e6db6a6f2556736a9bc280.js'),
    m = require('./949d8235c744ced2a80121e4dba34c28.js'),
    n = require('./common/locales/index.js'),
    o = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    p = require('./911222a6723da8db7ca8a8e3689591e1.js'),
    q = require('./e5fa35c3c8e81bc6466b4b8eb436113b.js'),
    r = require('./bcb48ae14d243711d3b31cb0f602d209.js'),
    s = require('./08cdbb558c25b102c0d6c3c9f05851aa.js'),
    t = () => ({ type: g.DEBUG_CUSTOM_ANALYSIS_CLOSE }),
    u = () => ({ type: g.DEBUG_MOBILE_TEST_CLOSE })
  module.exports = {
    openCustomAnalysis: () => (a, b) => {
      const { project: c, debug: d } = b()
      if (!c.current) return
      if (c.current.appid === f.TOURIST_APPID)
        return void a(
          h.setConfirmInfo({
            show: !0,
            showCancel: !1,
            title: n.config.ALERT_TOURIST_FORBIDDEN_TITLE,
            content: n.config.ALERT_TOURIST_FORBIDDEN_CONTENT
          })
        )
      let e
      ;(e = i.get('custom_analysis'))
        ? e.focus()
        : (d.customAnalysis.isOpen && a(t()),
          a({ type: g.DEBUG_CUSTOM_ANALYSIS_OPEN }))
    },
    closeCustomAnalysis: t,
    updateCustomAnalysisConfig: a => ({
      type: g.DEBUG_CUSTOM_ANALYSIS_UPDATE_CONFIG,
      config: a
    }),
    openMobileTest: () => (a, b) => {
      const { project: c, debug: d } = b()
      if (!c.current) return
      if (c.current.appid === f.TOURIST_APPID)
        return void a(
          h.setConfirmInfo({
            show: !0,
            showCancel: !1,
            title: n.config.ALERT_TOURIST_FORBIDDEN_TITLE,
            content: n.config.ALERT_TOURIST_FORBIDDEN_CONTENT
          })
        )
      let e
      ;(e = i.get(f.WINDOW_REGISTRY.MOBILE_TEST))
        ? e.focus()
        : (d.mobileTest.isOpen && a(u()), a({ type: g.DEBUG_MOBILE_TEST_OPEN }))
    },
    closeMobileTest: u,
    commitMobileTest: (e, f, g = !0) => i =>
      new Promise(async (t, u) => {
        try {
          s(
            {
              priority: 1,
              title: '\u5F00\u59CB\u7533\u8BF7\u6D4B\u8BD5',
              message: '\u5F00\u59CB\u7533\u8BF7\u6D4B\u8BD5'
            },
            {
              type: r.DBType.system,
              content: '\u5F00\u59CB\u7533\u8BF7\u6D4B\u8BD5',
              timestamp: Date.now() / 1e3
            },
            !0
          ),
            (e && f) || ((e = o.getCurrentConfig()), (f = o.getCurrent()))
          let u
          try {
            u = e.setting.MaxCodeSize
          } catch (a) {
            u = 1
          }
          let v = 1024 * (1024 * u),
            w = await p(f, { noCompile: !0 })
          const x = l.Weappdest
          let y = b.join(x, `${+new Date()}.wx`),
            z = await q(w, y),
            A = z.destPath,
            B = z.data
          c(w, () => {})
          let C = B.length
          if (C > v) {
            a.unlink(y, () => {})
            let b = new Error(
              n.config.CODE_SIZE_EXCEED.format([
                parseInt(C / 1024),
                parseInt(v / 1024)
              ])
            )
            throw ((b.code = m.CODE_SIZE_EXCEED), b)
          }
          let D = d.gzipSync(B),
            { body: E } = await j({
              url: `${k.commitMobileTest}?gzip=1&appid=${e.appid}`,
              method: 'post',
              body: D,
              needToken: 1
            })
          g && i(h.showSuccessTip('\u6D4B\u8BD5\u7533\u8BF7\u6210\u529F')), t()
        } catch (a) {
          u(a),
            g &&
              i(
                h.setConfirmInfo({
                  show: !0,
                  showCancel: !1,
                  content:
                    '\u6D4B\u8BD5\u7533\u8BF7\u5931\u8D25\uFF0C\u539F\u56E0\uFF1A' +
                    a.toString()
                })
              ),
            console.error(
              '\u81EA\u52A8\u5316\u6D4B\u8BD5\u7533\u8BF7\u5931\u8D25\uFF0C\u9519\u8BEF\u4FE1\u606F\uFF1A',
              a.toString()
            )
        }
      }),
    getMobileTestInfo: () => a =>
      new Promise(async (b, c) => {
        try {
          const { body: c } = await j({
            url: `${k.getMobileTestInfo}`,
            needToken: 1,
            needAppID: 1
          })
          b(c.test_list || []),
            a({ type: 'DEBUG_MOBILE_TEST_FETCH_LIST', list: c.test_list || [] })
        } catch (a) {
          c(a)
        }
      }),
    viewMobileTestReport: a => b =>
      new Promise(async () => {
        let c
        ;(c = i.get(`mobile_test_report_${a}`))
          ? c.window.focus()
          : b({ type: g.DEBUG_MOBILE_TEST_VIEW_REPORT, testid: a })
      }),
    closeMobileTestReport: a => ({
      type: g.DEBUG_MOBILE_TEST_CLOSE_REPORT,
      testid: a
    }),
    downloadAutoTestReport: () => () => new Promise(async () => {})
  }
})(require('lazyload'), require)
