'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('lodash'),
    b = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    c = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    d = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    e = require('./84858de8a097c9cf84ff2c2e3d86e2a9.js'),
    f = require('./cc2c2970ff81ae4a83123e81ee123da2.js'),
    g = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    h = require('./ba23d8b47b1f4ea08b9fd49939b9443f.js'),
    i = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    j = require('./d28a711224425b00101635efe1034c99.js'),
    k = require('./6242f55dbdfe53c2f07b7a51568311f2.js'),
    l = require('./551bb965e1f344281d555a429cd2140c.js'),
    m = require('./5719b6ded53098ffd9e848abcac30153.js'),
    n = require('./5eb00762b104199e0cf0af7efbe591da.js'),
    o = {
      network: {
        RequestDomain: [],
        WsRequestDomain: [],
        UploadDomain: [],
        DownloadDomain: []
      },
      setting: _extends({}, k.setting)
    },
    p = () => {
      try {
        const a = b.getState()
        a.window.simulator.show ||
          b.dispatch({ type: c.WINDOW_TOGGLE_SIMULATOR }),
          a.window.debug.show || b.dispatch({ type: c.WINDOW_TOGGLE_DEBUGGER })
      } catch (a) {}
    },
    q = (c, d, h, k = {}) =>
      new Promise(async (p, q) => {
        let r
        d.projectname &&
          (d.projectname = encodeURIComponent(
            decodeURIComponent(d.projectname)
          ))
        try {
          let s = !1
          if (!k.isTemp) {
            const a = e.projectList,
              b = `${d.appid}_${d.projectname}`
            for (let c in a)
              if (c == b) {
                ;(r = a[c]), (s = !0)
                break
              }
          }
          if (s) r.projectpath !== h && q(m.ERROR.DUPLICATE_PROJECT_ID())
          else {
            const e = `${d.appid}_${d.projectname}`
            r = _extends({}, d, {
              isAdmin: c.is_admin,
              isTourist: !1,
              isTemp: k.isTemp,
              isOnline: k.isOnline,
              urlCheck: !0,
              projectid: e,
              hash: i.strToHash(e),
              appid: d.appid,
              projectname: d.projectname,
              projectpath: h,
              appShowImageUrl: '',
              libVersion: j.getVendorConfig().currentLibVersion,
              attr: _extends({}, o, {
                platform: !!c.is_platform,
                platformNickname: c.platform_nickname || '',
                appNickName: ''
              })
            })
            const m = a.merge(g.projectConfigDefault(r), r)
            ;(r = m), r.compileType || (r.compileType = 'weapp')
            let p
            try {
              if (
                ((p = await n.getAppAttr(r)),
                (r.attr = _extends({}, r.attr, p)),
                c.is_platform)
              ) {
                const a = await l(r)
                a && a.extAppid && (r.attr.extInfo = { appid: a.extAppid })
              }
            } catch (a) {
              q(a)
            }
            k.isTemp
              ? (localStorage[`temp_${r.projectid}`] = JSON.stringify(r))
              : b.dispatch(f.createProjectSuccess(r))
          }
          p(r)
        } catch (a) {
          q(m.ERROR.GENERIC_ERROR(a.toString()))
        }
      })
  module.exports = {
    getProject: q,
    openProject: (a, c, d, e = {}) =>
      new Promise(async (g, h) => {
        try {
          const h = await q(a, c, d, e),
            i = () => {
              b.dispatch(f.openProject(h.projectid)).then(() => {
                setTimeout(() => {
                  p()
                }, 20)
              })
            }
          if (e.isTemp) b.dispatch(f.openTempProject(h))
          else {
            const a = b.getState()
            a.project && a.project.current
              ? (b.dispatch(f.closeProject()), setTimeout(i, 50))
              : i()
          }
          g()
        } catch (a) {
          h(a)
        }
      }),
    isOpened: (a, c) => {
      try {
        const d = b.getState().project.current
        return d.projectid === a && d.projectpath === c
      } catch (a) {
        return !1
      }
    },
    openSimulatorAndDebugger: p,
    compile: () => {
      try {
        b.dispatch(h.compile({ origin: d.COMPILE_ORIGIN.HTTP }))
      } catch (a) {}
    }
  }
})(require('lazyload'), require)
