'use strict'
!(function(require, directRequire) {
  const a = require('path'),
    b = require('react'),
    c = require('./0db6515f85d6f6210c2d50722041eb1f.js'),
    d = require('./d00040b9bed6196b3701ea7c8a4b4db3.js'),
    e = require('redux'),
    f = require('./9a24eb4fb7a49d4dd24531943fc3c899.js'),
    g = require('./ba23d8b47b1f4ea08b9fd49939b9443f.js'),
    h = require('classnames'),
    i = require('./ee4168d3d76e7e2f3fd66e4134821f90.js'),
    j = require('./1fcc6bd55b687d154a4247e57fe3011d.js'),
    k = require('./a15851ca252a104aad8b3fd3fc114574.js'),
    { connect: l } = require('react-redux')
  class m extends b.Component {
    constructor(a) {
      super(a)
    }
    componentDidMount() {
      ;(this._onMessage = this.onMessage.bind(this)),
        d.register(this._onMessage)
    }
    componentWillUnmount() {
      d.unRegister(this._onMessage)
    }
    componentWillReceiveProps(a) {
      ;((a.debuggee != this.props.debuggee && a.debuggee) ||
        (a.ready != this.props.ready && a.ready)) &&
        setTimeout(() => {
          this.changeDebuggee()
        }),
        a.wxmlInspected != this.props.wxmlInspected &&
          setTimeout(() => {
            this.inspectModeChange()
          })
    }
    changeDebuggee() {
      if (this.props.wxmlDebuggee && this.props.ready) {
        let a = this.props
        d.send({
          command: 'CHANGE_DEBUGGEE',
          data: {
            debuggee: a.wxmlDebuggee,
            debuggeeMap: a.debuggeeMap,
            device: a.device
          }
        }),
          this.props.wxmlInspected && this.inspectModeChange()
      }
    }
    async openEditorFile(b) {
      let c = this.props.project,
        d = c.miniprogramRoot
          ? a.posix.join(c.projectpath, c.miniprogramRoot)
          : c.projectpath,
        e = a.posix.relative(c.projectpath, a.posix.join(d, b.file))
      this.props.openEditorFile({ file: `/${e}`, line: parseInt(b.line) })
    }
    onMessage(a) {
      let { command: b, data: e } = a
      'GET_CURRENT_DEBUGGEE' === b
        ? ((d.ready = !0),
          setTimeout(() => {
            this.changeDebuggee()
          }))
        : 'SEND_COMMAND' === b
          ? global.useChromeRemoteDebugProtocal
            ? c.sendCommand(e.debuggee, e.method, e.commandParams, a => {
                d.send({
                  command: 'GET_DEVTOOLS_RES',
                  data: { res: a, callbackID: e.callbackID }
                })
              })
            : k.triggerOnEvent({
                webviewID: e.debuggee.targetId,
                eventName: 'remoteDebugCommand',
                data: {
                  method: e.method,
                  commandParams: e.commandParams,
                  callbackID: e.callbackID
                }
              })
          : 'OPEN_FILE' === b
            ? this.openEditorFile(e)
            : 'ON_PANEL_HIDE' === b ||
              ('HIDE_INSPECT_MODE' == b &&
                (this.props.wxmlInspected
                  ? this.props.setWxmlInspect(!1)
                  : this.hideInspectMode()))
    }
    hideInspectMode() {
      if (global.useChromeRemoteDebugProtocal) {
        let a = this.props.debuggee
        if (!a) return
        c.sendCommand(a, 'DOM.hideHighlight', {}, () => {}),
          c.sendCommand(a, 'Overlay.setInspectMode', { mode: 'none' }, () => {})
      }
      return (
        k.triggerOnEvent({
          webviewID: this.props.currentWebviewID,
          eventName: 'remoteDebugCommand',
          data: { method: 'DOM.hideHighlight', commandParams: {} }
        }),
        void k.triggerOnEvent({
          webviewID: this.props.currentWebviewID,
          eventName: 'remoteDebugCommand',
          data: {
            method: 'Overlay.setInspectMode',
            commandParams: { mode: 'none' }
          }
        })
      )
    }
    inspectModeChange() {
      let a = this.props.debuggee
      a &&
        (this.props.wxmlInspected
          ? global.useChromeRemoteDebugProtocal
            ? c.sendCommand(
                a,
                'Overlay.setInspectMode',
                { mode: 'searchForNode', highlightConfig: i },
                () => {}
              )
            : k.triggerOnEvent({
                webviewID: this.props.currentWebviewID,
                eventName: 'remoteDebugCommand',
                data: {
                  method: 'Overlay.setInspectMode',
                  commandParams: { mode: 'searchForNode', highlightConfig: i }
                }
              })
          : this.hideInspectMode(),
        d.send({ command: 'SET_INSPECT_MODE', data: this.props.wxmlInspected }))
    }
    inspectorWxml() {
      this.props.debuggee &&
        (!this.props.wxmlInspected &&
          f.send({ command: 'SHOW_PANNEL', data: { name: 'Wxml' } }),
        this.props.setWxmlInspect(!this.props.wxmlInspected))
    }
    render() {
      return b.createElement(
        'div',
        { style: { position: 'absolute', width: 35, height: 28, zIndex: 2 } },
        b.createElement('div', { className: 'devtools-inspector-bg' }),
        b.createElement('div', {
          className: h('devtools-inspector', {
            active: this.props.wxmlInspected
          }),
          onClick: this.inspectorWxml.bind(this)
        })
      )
    }
  }
  module.exports = l(
    a => {
      let b = a.simulator.currentWebviewID,
        c = a.simulator.debuggeeMap,
        d = c[b],
        e = d,
        f = a.simulator.webviewInfos,
        g = f[b] || {},
        h = a.toolbar.deviceInfo || {},
        i = {}
      if (!global.useChromeRemoteDebugProtocal) {
        for (let a in f) f[a] && (i[a] = { targetId: a + '' })
        e = { targetId: b + '' }
      } else
        for (let a in c) {
          let b = c[a]
          b && (i[b.targetId] = b)
        }
      return {
        device: { width: h.screenWidth, dpr: h.dpr },
        project: a.project.current,
        ready: g.ready,
        wxmlInspected: a.simulator.wxmlInspected,
        debuggeeMap: i,
        wxmlDebuggee: e,
        currentWebviewID: b,
        debuggee: d,
        webviewInfos: f
      }
    },
    a => {
      return {
        setWxmlInspect: b => {
          a(g.setWxmlInspect(b))
        },
        openEditorFile: b => {
          a(j.openEditorFile(b))
        }
      }
    }
  )(m)
})(require('lazyload'), require)
