'use strict'
!(function(require, directRequire) {
  const a = require('react'),
    b = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    c = require('./c4190a2430506f3602ca550e1e75d620.js'),
    d = require('./a8c87029da0fa06e986298d447ab0fe2.js'),
    e = require('./4762f28cad4425c4fc55dec009c87a7e.js'),
    { connect: f } = require('react-redux')
  class g extends a.Component {
    componentDidMount() {
      this.initWebview(),
        (this._onDevtoolsMessage = this.onDevtoolsMessage.bind(this)),
        e.register(this._onDevtoolsMessage)
    }
    componentWillReceiveProps(a) {
      a.webview != this.props.webview &&
        a.webview &&
        setTimeout(() => {
          this.showDevTools()
        }),
        a.device != this.props.device &&
          setTimeout(() => {
            this.setDevice()
          })
    }
    componentWillUnmount() {
      e.unRegister(this._onDevtoolsMessage)
    }
    onDevtoolsMessage(a) {
      'Button.popup' === a.command &&
        this.props.windowActions.setDebuggerWindow({ popup: !this.props.popup })
    }
    initWebview() {
      let a = (this.devtoolsview = document.createElement('webview'))
      a.setAttribute('partition', 'persist:devtools'),
        a.setAttribute('style', 'height:100%;width:100%;position:relative;')
      let b = `${a.getUserAgent()} devtoolsview port/${
        global.messageCenterPort
      }`
      a.setUserAgentOverride(b),
        this.container.appendChild(a),
        this.props.webview && this.showDevTools()
    }
    setDevice() {
      const a = this.props
      e.send({
        command: 'SET_DEVICE',
        data: {
          width: 0,
          height: 0,
          deviceScaleFactor: parseFloat(a.dpr),
          mobile: !0,
          fitWindow: !1,
          scale: 1,
          screenHeight: parseInt(a.height),
          screenWidth: parseInt(a.width),
          positionX: 0,
          positionY: 0,
          screenOrientation: { angle: 0, type: 'portraitPrimary' }
        }
      })
    }
    _newwindow(a) {
      a.preventDefault()
      let b = a.targetUrl
      b &&
        ('https://developers.google.com/web/tools/chrome-devtools/' === b &&
          (b = 'https://mp.weixin.qq.com/debug/wxadoc/dev/index.html'),
        'https://developers.google.com/web/updates/2017/05/devtools-release-notes' ===
          b &&
          (b = 'https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/new.html'),
        nw.Window.open(b, { width: 799, height: 799 }))
    }
    showDevTools() {
      let a = this.props.webview,
        b = this.devtoolsview
      const c = () => {
        b.removeEventListener('loadcommit', c)
        const d = () => {
          a.removeEventListener('loadcommit', d), a.showDevTools(!0, b)
        }
        a.addEventListener('loadcommit', d), (a.src = 'html/about.html')
      }
      b.addEventListener('loadcommit', c),
        b.addEventListener('contentload', () => {
          this.setDevice()
        }),
        (b.src = 'about:blank'),
        b.addEventListener('newwindow', this._newwindow)
    }
    render() {
      return a.createElement('div', {
        ref: a => (this.container = a),
        style: { flex: 1, height: this.props.isPopup ? '100%' : 'inherit' },
        className: 'devtools'
      })
    }
  }
  module.exports = f(
    a => {
      let b = a.webdebugger || {},
        c = a.toolbar.deviceInfo
      return {
        device: c,
        dpr: c.dpr,
        height: c.screenHeight - c.navigationbarHeight - c.statusbarHeight,
        width: c.screenWidth,
        webview: b.webview,
        popup: a.window.debug.popup
      }
    },
    a => {
      return {
        debuggerActions: b.bindActionCreators(c, a),
        windowActions: b.bindActionCreators(d, a)
      }
    }
  )(g)
})(require('lazyload'), require)
