'use strict'
!(function(require, directRequire) {
  const a = require('./205e69607c4b60711b15f5ac95b40ce4.js'),
    b = require('./c016c015550b8c8e4a79e8e85062bd17.js'),
    c = require('./76d9df7b0b3e47fbe17881420a4bef86.js'),
    d = require('./36e525c1a6e2426c7d997e7f9a8c6422.js'),
    e = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    f = require('./09060286633d09fb81fefc8ff1294dd7.js'),
    g = require('./b543ae2da406cea63b3ad8951f17b6c0.js'),
    h = e.dispatch.bind(e)
  module.exports = {
    [b.Name.GET]: async (b, e) => {
      const { appid: f, newWindow: h, url: i } = e
      if (!f || !i)
        return {
          status: c.JavaScriptError,
          value: { message: `Lack of appid / projectpath, cannot open project` }
        }
      const j = e.options || {}
      ;(j.appid = f),
        (j.newWindow = h),
        global.online &&
          g.clientWindows.forEach((a, b) => {
            g.closeDevWindow(b)
          })
      let k
      try {
        k = await d.openProject(i, j)
      } catch (a) {
        return {
          status: c.JavaScriptError,
          value: { message: `Open project failed with error: ${a.toString()}` }
        }
      }
      try {
        const a = 3e4
        await Promise.race([
          g.onceCliPortUpdate({ projectid: k }),
          new Promise((b, c) =>
            setTimeout(
              () =>
                c(`client window (${k}) did not started within ${a / 1e3}s`),
              a
            )
          )
        ])
      } catch (a) {
        return { status: c.JavaScriptError, value: { message: a.toString() } }
      }
      const l = g.getClientIdByProjectId(k)
      return l
        ? (a.addWindowHandle(l),
          a.setCurrentBrowsingContext(l),
          new Promise(a => {
            setTimeout(() => {
              a({ status: c.Success })
            }, 1e3)
          }))
        : {
            status: c.JavaScriptError,
            value: {
              message: `Did not found client window for project with id ${l}`
            }
          }
    },
    [b.Name.GET_CURRENT_URL]: async () => {
      const a = e.getState()
      return {
        status: c.Success,
        value:
          (a.project && a.project.current && a.project.current.projectpath) ||
          ''
      }
    }
  }
})(require('lazyload'), require)
