'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('path'),
    b = require('react'),
    { connect: c } = require('react-redux'),
    d = require('prop-types'),
    f = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    e = require('./a8c87029da0fa06e986298d447ab0fe2.js'),
    g = require('./ba23d8b47b1f4ea08b9fd49939b9443f.js'),
    h = require('./e98c60a262d8d98e69e574a9d12a21df.js'),
    i = require('./5451dfc4d939398d913dc724d952b02b.js'),
    j = require('./6620a0cf7dad1b400d60f0fdae40f524.js'),
    k = require('./efaddce19b790978e16990920754b000.js'),
    l = require('./584aae91d7c83393222029103ba1ac29.js'),
    m = require('./925e13dda17a5a2e1cbaf0212c56c31c.js'),
    n = require('./0df497a6fb76113a0a8e66dad897263e.js'),
    o = require('./aee2b6963336bb84d2ce0e0ed38dae60.js'),
    p = require('redux'),
    q = require('./0ac4da1c7ab84710f2c94e3bf0cf4861.js'),
    r = require('./3274726e14e61776145df49bcfdcf89c.js'),
    s = require('./fe312864f5142b11bfe28ad1bc5ad2f8.js'),
    t = require('./a1fed34995a9fdae4b41f1acb9c2e5a9.js'),
    u = require('./d3ca3f15cb99fc14bb8fbfeeb32ad0f5.js'),
    v = require('./444cd5bc8c3d312afefcdada704d0f95.js'),
    w = require('./b1ba6dfcea5ed09bd8f7edf39a8149d6.js'),
    x = require('./7d9f39319673925120c4a1020d58dbd7.js'),
    y = require('./a3b5b3f603a2b65817dc1171b7ec7a8d.js'),
    z = require('./a254abb81b6346b59aa82a08652fe610.js'),
    A = require('./d51f6457067a06cf51fac263b2c25b60.js'),
    B = require('./8e764a20d4ff4876a256ceb36e40c37e.js'),
    C = require('./da7c31daaf542cf1796023d8e344b98a.js'),
    D = require('./d326caa17e34aabeda5187fbed6e1e47.js'),
    E = require('./af9e5b2040c286e3da6d2e3b30eae482.js'),
    F = require('./00bb746364abbf48ca081de687ce505a.js'),
    G = require('./59aba0523016c691a75262d7f9a6b793.js'),
    H = require('./bf5bd8b977a68a4f788a29b92aa86a0e.js'),
    I = require('./d24cc22e4b11eda71b5615ee005c61df.js'),
    J = require('./c465c4038a3000251743734c502c80ed.js'),
    K = require('./5fce949eb42d709c19a90da9440a955b.js'),
    L = require('./3abac29230bbc52f03349d2cd4796dd0.js'),
    M = require('./dc59f57d54946e61d27c95ab24d8cb4f.js'),
    N = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    O = require('./9fdd4ac31a05c27355910f0d74accd4c.js'),
    P = require('./3b66d845db4d098b7a16cb0357f5c072.js'),
    Q = require('./eadce02c750c875a10680bcfedadec88.js'),
    R = require('./2a36cc34e5f44e62f9188b9fc0871d70.js'),
    S = require('./3b4ae76898f5e38e0fa745be867d8de3.js'),
    T = require('./37d8b9297fb1bd87f9a3ac407b8006a0.js'),
    U = require('./cc2c2970ff81ae4a83123e81ee123da2.js'),
    V = require('./f4b122ca93225892eb1487c959c929f6.js'),
    W = require('./d62fc37d7aa6416d5dcc240ba94175cd.js'),
    X = require('./106eac0139723db6a35b934f19cb4aa5.js'),
    Y = require('./03b7faa8f76486fc3878b17c9a674a7e.js'),
    Z = require('./5dc59f418d85e854c1a12d402d29e2d7.js'),
    $ = require('./bc0aa9e11159f5769f00d6e8f5ac5aae.js'),
    _ = require('./1fcc6bd55b687d154a4247e57fe3011d.js'),
    aa = require('./42191d95974f14b18961c9f2c730464e.js'),
    ba = 'darwin' === process.platform
  class ca extends b.Component {
    constructor(a) {
      super(a),
        (this.state = {}),
        (this.lastWorkbenchShowWindowWidth = 0),
        (this._onConfigUpdate = this.onConfigUpdate.bind(this)),
        (this.reportMemoryTimer = null),
        (this.lastReportMemory = 0),
        (this.lastReportMemoryTime = 0),
        (this._onResize = this.onResize.bind(this)),
        (this._onMove = this.onMove.bind(this))
    }
    componentDidMount() {
      if (this.props.win || global.isDevWindow) {
        const a = this.props.win || global.Win
        global.windowMap.set('MAIN', a),
          global.online ||
            a.setMinimumSize(f.MIN_MAIN_WINDOW_WIDTH, f.MIN_MAIN_WINDOW_HEIGHT),
          a.on('resize', this._onResize),
          i.init(a),
          i.update()
      }
      let a = M.get()
      a && a.scene && this.props.updateSceneConfig(a),
        R.startSync(),
        S.startSync(),
        M.on('CONFIG_UPDATE', this._onConfigUpdate),
        (this.reportMemoryTimer = setInterval(
          this.reportMemory.bind(this),
          300000
        )),
        this.props.requestProjectAttr(),
        this.watchProjectConfig()
    }
    componentWillUnmount() {
      M.off('CONFIG_UPDATE', this._onConfigUpdate),
        R.stopSync(),
        S.stopSync(),
        clearInterval(this.reportMemoryTimer)
    }
    componentWillReceiveProps(a) {
      a.workbenchShow != this.props.workbenchShow &&
        (a.workbenchShow
          ? (global.Win.width = Math.max(
              this.lastWorkbenchShowWindowWidth,
              global.Win.width,
              a.simulatorWindowWidth + 100
            ))
          : ((this.lastWorkbenchShowWindowWidth = global.Win.width),
            (global.Win.width = a.simulatorWindowWidth)))
    }
    getChildContext() {
      return { currentNWWindow: this.props.win ? this.props.win : global.Win }
    }
    async watchProjectConfig() {
      let b = this.props.project
      ;(this.projectFiles = await W(b.projectpath)),
        this.projectFiles.on('all', (c, d) => {
          ;(d = a.relative(b.projectpath, d)),
            'project.config.json' == d && this.projectConfigFileChanged()
        }),
        this.projectConfigFileChanged()
    }
    async projectConfigFileChanged() {
      const a = this.props.project,
        b = aa.getConfigFileInfo(a)
      if (!b.error) this.props.setProjectConfig(b.config)
      else {
        let a = null
        'readerror' === b.error.type
          ? (a = {
              title: '',
              content:
                '\u8BFB\u53D6 project.config.json \u6587\u4EF6\u5931\u8D25\u3002',
              showCancel: !1
            })
          : 'parseerror' === b.error.type
            ? (a = {
                title: '',
                content:
                  '\u89E3\u6790 project.config.json \u6587\u4EF6\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u5176\u5185\u5BB9\u6216\u5220\u9664\u6B64\u6587\u4EF6\u3002',
                showCancel: !1
              })
            : 'contenterror' === b.error.type &&
              (a = {
                title: '',
                content: `解析 project.config.json 文件失败，${
                  b.error.message
                }`,
                showCancel: !1
              }),
          a && this.props.confirm(a)
      }
    }
    onResize(a, b) {
      this.resizeTimer && clearTimeout(this.resizeTimer),
        (this.resizeTimer = setTimeout(() => {
          this.props.windowActions.appResize({ width: a, height: b }),
            (this.resizeTimer = null)
        }, 20))
    }
    onMove(a, b) {
      this.moveTimer && clearTimeout(this.moveTimer),
        (this.moveTimer = setTimeout(() => {
          this.props.windowActions.appResize({ x: a, y: b }),
            (this.moveTimer = null)
        }, 20))
    }
    checkWindowStatus() {
      let a = this.props.windowStatus.mode
      if (a == f.WINDOW_MODE.FULLSCREEN) this.props.win.enterFullscreen()
      else if (a == f.WINDOW_MODE.WINDOW_MAXIMIZE) this.props.win.maximize()
      else if (a == f.WINDOW_MODE.FREE) {
        let a = this.props.windowStatus.position
        this.props.win.moveTo(a.x, a.y),
          this.props.win.resizeTo(a.width, a.height)
      }
    }
    onBodyClick(a) {
      this.props.clickkey != Q.NONE && this.props.bodyClick(a),
        a.target.partition
          ? 'persist:editor' === a.target.partition
            ? this.props.recordFocus(f.WINDOW_FOCUS.EDITOR)
            : 'persist:devtools' === a.target.partition
              ? this.props.recordFocus(f.WINDOW_FOCUS.DEVTOOLS)
              : 'persist:remotedebugdevtools' === a.target.partition &&
                this.props.recordFocus(f.WINDOW_FOCUS.REMOTE_DEBUG_DEVTOOLS)
          : this.props.recordFocus(f.WINDOW_FOCUS.BODY)
    }
    reportMemory() {
      chrome.processes.getProcessInfo([], !0, a => {
        let b = 0
        for (let c in a) {
          let d = a[c]
          d.privateMemory && (b += d.privateMemory)
        }
        b = parseInt(b / 1024 / 1024)
        isNaN(b) ||
          ((Date.now() - this.lastReportMemoryTime > 7200000 ||
            100 < Math.abs(b - this.lastReportMemory)) &&
            (console.log(
              'memory_monitor',
              this.props.project.appid,
              `${b},${this.props.restartTimes}`
            ),
            C(
              'memory_monitor',
              this.props.project.appid,
              `${b},${this.props.restartTimes}`
            ),
            (this.lastReportMemoryTime = Date.now()),
            (this.lastReportMemory = b)))
      })
    }
    onConfigUpdate(a) {
      this.props.updateSceneConfig(a)
    }
    onAboutClick() {
      this.props.windowActions.setAboutWindow({ show: !0 })
    }
    onSimulatorWindowReady() {
      'popup' === this.props.simulatorPosition &&
        this.props.simulatorActions.compile()
    }
    onDevtoolsWindowReady() {}
    onSimulatorWindowClose() {
      this.props.windowActions.setSimulatorPosition('left')
    }
    onDevtoolsWindowClose() {
      this.props.windowActions.setDebuggerWindow({ popup: !1 })
    }
    getSimulator(a) {
      let c = this.props,
        d = c.simulatorWindowWidth
      if (
        (c.simulatorShow ? !c.workbenchShow && (d = '100%') : (d = 0),
        'popup' === c.simulatorPosition)
      ) {
        let d
        if (c.project.attr && c.project.attr.gameApp)
          d = a == O.conversation || a == O.search ? y : z
        else
          switch (a) {
            case O.weapp:
            case O.plugin: {
              d = l
              break
            }
            case O.search:
            case O.conversation: {
              d = y
              break
            }
            default:
              return null
          }
        const e = {
          className: 'standalone',
          onClick: this.onBodyClick.bind(this)
        }
        return b.createElement(j, {
          templateHTML: 'html/standalone.html',
          wrapperProps: e,
          title: `${decodeURIComponent(c.project.projectname)}的模拟器`,
          frame: !0,
          show: !1,
          width: c.deviceWidth,
          height: c.deviceHeight + 27,
          resizable: !1,
          fullscreen: !1,
          always_on_top: !1,
          onWindowClose: this.onSimulatorWindowClose.bind(this),
          onReady: this.onSimulatorWindowReady.bind(this),
          renderClass: d
        })
      }
      return c.project.attr && c.project.attr.gameApp
        ? a == O.conversation || a == O.search
          ? b.createElement(y, { width: d })
          : b.createElement(z, { width: d })
        : a === O.weapp || a === O.plugin
          ? b.createElement(l, { width: d })
          : a === O.search || a === O.conversation
            ? b.createElement(y, { width: d })
            : null
    }
    getService(a) {
      let c = this.props,
        d = c.debuggerHeight
      if (c.debuggerPopup) {
        let e
        if (
          (c.project.attr &&
            c.project.attr.gameApp &&
            (a == O.conversation || a == O.search ? (e = x) : (e = A)),
          !e)
        )
          switch (a) {
            case O.weapp:
            case O.plugin: {
              e = w
              break
            }
            case O.search:
            case O.conversation: {
              e = x
              break
            }
            default:
              return null
          }
        return b.createElement(j, {
          title: `${decodeURIComponent(c.project.projectname)}的调试器`,
          frame: !0,
          show: !1,
          height: d,
          resizable: !0,
          fullscreen: !1,
          always_on_top: !1,
          onWindowClose: this.onDevtoolsWindowClose.bind(this),
          onReady: this.onDevtoolsWindowReady.bind(this),
          renderClass: e,
          renderProps: { height: d }
        })
      }
      return c.project.attr && c.project.attr.gameApp
        ? a == O.conversation || a == O.search
          ? b.createElement(x, { height: d })
          : b.createElement(A, { height: d })
        : a === O.weapp || a === O.plugin
          ? b.createElement(w, { height: d })
          : a === O.search || a === O.conversation
            ? b.createElement(x, { height: d })
            : null
    }
    getOptionsComponents() {
      let a = this.props,
        c = []
      return (
        a.shareInfoShow && c.push(b.createElement(E, { key: 'share' })),
        a.uploadinfoShow && c.push(b.createElement(F, { key: 'upload' })),
        a.uploadPluginDocInfoShow &&
          c.push(b.createElement(G, { key: 'uploadplugindoc' })),
        a.noticecenterShow &&
          c.push(b.createElement(B, { key: 'noticecenter' })),
        a.addDeviceShow && c.push(b.createElement(X, { key: 'adddevice' })),
        a.qcloudUploadDialogShow &&
          c.push(b.createElement(s, { key: 'qclouduploaddialog' })),
        a.qcloudDeployDialogShow &&
          c.push(b.createElement(v, { key: 'qclouddeploydialog' })),
        a.qcloudUploadIDCShow &&
          c.push(b.createElement(t, { key: 'qclouduploadidc' })),
        a.musicShow && c.push(b.createElement(Y, { key: 'music' })),
        a.iconManagerShow && c.push(b.createElement(r, { key: 'iconmanager' })),
        a.showCosManager && c.push(b.createElement($, { key: 'cos' })),
        a.confirmShow && c.push(b.createElement(H, { key: 'confirm' })),
        c
      )
    }
    render() {
      let a = this.props,
        c = a.project.compileType,
        d = 'workbench'
      a.workbenchShow || (d += ' ui-invisible')
      let e = null
      return (
        this.props.maskType &&
          this.props.maskType === f.MASK_TYPE.GLOBAL_BLOCKING &&
          (e = b.createElement('div', {
            className: 'ui-mask ui-mask-transparent'
          })),
        b.createElement(
          'div',
          {
            style: { height: 'inherit' },
            onClick: this.onBodyClick.bind(this)
          },
          b.createElement(m, null),
          b.createElement(
            'div',
            {
              className:
                'left' === a.simulatorPosition ? 'main' : 'main main-reverse'
            },
            b.createElement(q, { compileType: c, project: this.props.project }),
            this.getOptionsComponents(),
            b.createElement(
              'div',
              { onMouseDown: this.onBodyClick.bind(this) },
              this.getSimulator(c)
            ),
            b.createElement(
              'div',
              { className: d, onMouseDown: this.onBodyClick.bind(this) },
              global.onlySimulator ? null : b.createElement(k, null),
              this.getService(c)
            ),
            b.createElement(D, null),
            a.showQCloudUploading ? b.createElement(u, null) : null,
            a.showCustomAnalysis ? b.createElement(n, null) : null,
            a.showMobileTest ? b.createElement(o, null) : null,
            a.showSelectProject ? b.createElement(I, { detach: !0 }) : null,
            a.showCreateProject ? b.createElement(J, { detach: !0 }) : null,
            a.showRemoteDebugWindow ? b.createElement(K, null) : null,
            a.showQCloudDebugWindow ? b.createElement(L, null) : null
          ),
          b.createElement(V, null),
          e
        )
      )
    }
  }
  ;(ca.childContextTypes = { currentNWWindow: d.object }),
    (module.exports = c(
      a => {
        let b = a.window.debug || {},
          c = a.window.editor || {},
          d = a.window.simulator || {},
          e = a.info.shareInfo || {},
          f = a.info.uploadInfo || {},
          g = a.info.uploadPluginDocInfo || {},
          h = a.info.confirmInfo || {},
          i = a.toolbar.deviceInfo || {},
          j = a.toolbar.clickKey,
          k = a.simulator.music && a.simulator.music.status
        return {
          debuggerHeight: b.height || 100,
          debuggerPopup: b.popup,
          simulatorWindowWidth: d.width || 500,
          workbenchShow: (b.show && !b.popup) || (c.show && !c.popup),
          simulatorShow: d.show,
          simulatorPosition: d.position,
          shareInfoShow: e.show,
          uploadinfoShow: f.show,
          uploadPluginDocInfoShow: g.show,
          deviceWidth: i.screenWidth,
          deviceHeight: i.screenHeight,
          addDeviceShow: a.info.addDeviceInfo && a.info.addDeviceInfo.show,
          noticecenterShow: Q.NOTICECENTER == j || Q.LOGINQRCODE == j,
          clickkey: j,
          confirmShow: h.show,
          maskType: a.window.mask.show ? a.window.mask.type : '',
          showCustomAnalysis: a.debug.customAnalysis.isOpen,
          showMobileTest: a.debug.mobileTest.isOpen,
          showCosManager: a.cos.show,
          showSelectProject:
            !!a.window.popup.selectProject && a.window.popup.selectProject.show,
          showCreateProject:
            !!a.window.popup.createProject && a.window.popup.createProject.show,
          showRemoteDebugWindow: !!a.window.remoteDebugWindow.show,
          showQCloudDebugWindow: !!a.window.qcloudDebugWindow.show,
          showQCloudUploading:
            a.window.qcloud.uploading && a.window.qcloud.uploading.show,
          project: a.project.current || {},
          restartTimes: a.simulator.restartTimes,
          windowStatus: a.window.windowStatus,
          qcloudUploadIDCShow: a.window.qcloud.uploadIDCShow,
          qcloudUploadDialogShow: a.window.qcloud.uploadShow,
          qcloudDeployDialogShow: a.window.qcloud.deployShow,
          iconManagerShow:
            a.window.toolbarConfig && a.window.toolbarConfig.show,
          musicShow: k == Z.MUSIC_STATE_PLAY || k == Z.MUSIC_STATE_PAUSE
        }
      },
      a => {
        return {
          bodyClick: b => {
            a(T.bodyClick(b))
          },
          recordFocus: b => a(e.recordFocus(b)),
          maximizeWindow: () => a(e.appMax()),
          requestProjectAttr: () => {
            a(U.requestProjectAttr())
          },
          windowActions: N.bindActionCreators(e, a),
          simulatorActions: N.bindActionCreators(g, a),
          updateSceneConfig: N.bindActionCreators(P.updateSceneConfig, a),
          setProjectConfig: N.bindActionCreators(U.setProjectConfig, a),
          confirm(b, c) {
            a(
              _.setConfirmInfo(
                _extends({ show: !0, showCancel: !1, callback: c }, b)
              )
            )
          }
        }
      }
    )(ca))
})(require('lazyload'), require)
