'use strict'
!(function(require, directRequire) {
  function a(a) {
    return {
      debugShow: a.window.debug && a.window.debug.show,
      debugPopup: a.window.debug && a.window.debug.popup,
      simulatorShow: a.window.simulator && a.window.simulator.show,
      simulatorPopup:
        a.window.simulator && 'popup' === a.window.simulator.position,
      editorShow:
        a.window.mainWindow !== c.MAIN_WINDOW_TYPE.WEB_DEBUGGER &&
        a.window.editor &&
        a.window.editor.show,
      editorPopup:
        a.window.mainWindow !== c.MAIN_WINDOW_TYPE.WEB_DEBUGGER &&
        a.window.editor &&
        a.window.editor.popup
    }
  }
  const b = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    c = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    d = require('./84858de8a097c9cf84ff2c2e3d86e2a9.js'),
    e = require('./db2217eb4cff896bdcbc50abe005058f.js'),
    f = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    g = require('./da7c31daaf542cf1796023d8e344b98a.js'),
    h = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    i = c => (d, e) => {
      const f = e(),
        g = a(f)
      ;(g.simulatorPopup ||
        'popup' !== c ||
        (g.debugShow && !g.debugPopup) ||
        (g.editorShow && !g.editorPopup)) &&
        d({ type: b.WINDOW_SET_SIMULATOR_POSITION, position: c })
    }
  module.exports = {
    appMax: () => {
      return a => {
        global.Win.maximize(), a({ type: b.WINDOW_MAXIMIZE })
      }
    },
    appMin: () => {
      return (a, d) => {
        try {
          if (d().window.windowStatus.mode === c.WINDOW_MODE.MIN) return
        } catch (a) {}
        global.Win.minimize(), a({ type: b.WINDOW_MINIMIZE })
      }
    },
    appFullscreen: () => {
      return a => {
        a({ type: b.WINDOW_FULLSCREEN })
      }
    },
    appResize: a => {
      return c => {
        c({ type: b.WINDOW_RESIZE, position: a })
      }
    },
    recordFocus: a => (c, d) => {
      const e = d()
      a !== e.window.focus && c({ type: b.WINDOW_RECORD_FOCUS, focus: a })
    },
    setMask: (a, d = c.MASK_TYPE.GLOBAL_BLOCKING) => {
      return { type: b.WINDOW_SET_MASK, maskType: d, show: a }
    },
    setMainWindow: a => e => {
      ;(a !== c.MAIN_WINDOW_TYPE.WEB_DEBUGGER ||
        a !== c.MAIN_WINDOW_TYPE.DEV) &&
        (d.lastSelect = null),
        e({ type: b.WINDOW_SET_MAIN_WINDOW, mainWindow: a })
    },
    setAboutWindow: a => {
      return { type: b.WINDOW_SET_ABOUT, data: a }
    },
    setDebuggerWindow: c => (d, e) => {
      const f = e(),
        i = a(f)
      if (!i.debugPopup) {
        const a = h.getCurrent()
        g(c.show ? 'weapp_open_simulator' : 'weapp_close_simulator', a.appid)
      }
      ;(!i.debugPopup &&
        (!1 === c.show || c.popup) &&
        (!i.simulatorShow || i.simulatorPopup) &&
        (!i.editorShow || i.editorPopup)) ||
        d({ type: b.WINDOW_SET_DEBUGGER, data: c })
    },
    setSimulator: (c = {}) => (d, e) => {
      const f = e(),
        i = a(f)
      if (!i.debugPopup) {
        const a = h.getCurrent()
        g(c.show ? 'weapp_open_simulator' : 'weapp_close_simulator', a.appid)
      }
      ;(i.simulatorPopup ||
        !1 !== c.show ||
        'popup' !== c.position ||
        (i.debugShow && !i.debugPopup) ||
        (i.editorShow && !i.editorPopup)) &&
        d({ type: b.WINDOW_SET_SIMULATOR, data: c })
    },
    setCustomCompile: a => {
      return { type: b.WINDOW_SET_CUSTOMCOMPILE, data: a }
    },
    setQCloud: a => {
      return { type: b.WINDOW_SET_QCLOUD, data: a }
    },
    setProjectManagement: a => async (d, f) => {
      if (a.show) {
        const a = f()
        if (a.window.projectManagement.show)
          try {
            const a = await e.onWindowRegistered(
              c.WINDOW_REGISTRY.PROJECT_MANAGEMENT
            )
            return void a.window.focus()
          } catch (a) {}
      }
      d({ type: b.WINDOW_SET_PROJECT_MANAGEMENT, data: a })
    },
    setRemoteDebugWindow: a => async (d, f) => {
      if (a.show) {
        const a = f()
        if (a.window.remoteDebugWindow.show)
          try {
            const a = await e.onWindowRegistered(
              c.WINDOW_REGISTRY.REMOTE_DEBUG_WINDOW
            )
            return void a.window.focus()
          } catch (a) {}
      }
      d({ type: b.WINDOW_SET_REMOTE_DEBUG_WINDOW, data: a })
    },
    setQCloudDebugWindow: a => async (d, f) => {
      if (a.show) {
        const a = f()
        if (a.window.qcloudDebugWindow.show)
          try {
            const a = await e.onWindowRegistered(
              c.WINDOW_REGISTRY.QCLOUD_DEBUG_WINDOW
            )
            return void a.window.focus()
          } catch (a) {}
      }
      d({ type: b.WINDOW_SET_QCLOUD_DEBUG_WINDOW, data: a })
    },
    setEditor: a => {
      return { type: b.WINDOW_SET_EDITOR, data: a }
    },
    toggleDebugWindow: () => (c, d) => {
      const e = d(),
        f = a(e)
      if (!f.debugPopup) {
        const a = h.getCurrent()
        g(f.debugShow ? 'weapp_close_devtools' : 'weapp_open_devtools', a.appid)
      }
      ;(f.debugShow &&
        !f.debugPopup &&
        (!f.simulatorShow || f.simulatorPopup) &&
        (!f.editorShow || f.editorPopup)) ||
        c({ type: b.WINDOW_TOGGLE_DEBUGGER })
    },
    toggleSimulatorWindow: () => (c, d) => {
      const e = d(),
        f = a(e)
      if (!f.debugPopup) {
        const a = h.getCurrent()
        g(
          f.simulatorShow ? 'weapp_close_simulator' : 'weapp_open_simulator',
          a.appid
        )
      }
      ;(f.simulatorShow &&
        !f.simulatorPopup &&
        (!f.debugShow || f.debugPopup) &&
        (!f.editorShow || f.editorPopup)) ||
        c({ type: b.WINDOW_TOGGLE_SIMULATOR })
    },
    toggleSimulatorPosition: () => {
      return { type: b.WINDOW_TOGGLE_SIMULATOR_POSITION }
    },
    toggleSimulatorPopup: () => (a, b) => {
      const c = b()
      'popup' === c.window.simulator.position ? a(i('left')) : a(i('popup'))
    },
    setSimulatorPosition: i,
    toggleEditorWindow: () => {
      const a = f.getState(),
        c = h.getCurrent(),
        d = a.window.editor && a.window.editor.show
      return (
        g(d ? 'weapp_close_editor' : 'weapp_open_editor', c.appid),
        { type: b.WINDOW_TOGGLE_EDITOR }
      )
    },
    toggleMiniMode: () => {
      return { type: b.WINDOW_TOGGLE_MINI_MODE }
    },
    setQCloudActionType: a => {
      return { type: b.WINDOW_SET_QCLOUD_ACTION, data: a }
    },
    toggleToolbar: () => {
      return { type: b.WINDOW_TOGGLE_TOOLBAR }
    },
    clearMiniCodeOptions: () => {
      return { type: b.WINDOW_CLEAR_MINICODE_OPTIONS }
    },
    syncWindow: (a = {}, c) => d => {
      d({ type: b.WINDOW_SYNC_STORE, data: a, syncTime: c })
    },
    setToolbarConfig: a => {
      return { type: b.WINDOW_TOOLBAR_CONFIG, data: a }
    }
  }
})(require('lazyload'), require)
