'use strict'
!(function(require, directRequire) {
  const a = require('react'),
    { connect: b } = require('react-redux'),
    c = require('./579ff317e2bba616b0afc89a505c4f3e.js'),
    d = require('./db2217eb4cff896bdcbc50abe005058f.js'),
    e = require('./6ff091369f442a4678a2ed4a1f758495.js'),
    f = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    g = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    h = require('./ff946754202ecf377034d29daac7c8d9.js'),
    i = require('./a1dd553cc059d528bb0ef56afed53968.js'),
    j = require('./84858de8a097c9cf84ff2c2e3d86e2a9.js'),
    k = a => Object.prototype.toString.call(a).slice(8, -1)
  class l extends a.Component {
    constructor(a) {
      super(a), (this.state = { open_ticket: '' })
    }
    componentDidMount() {
      this.getTicket(), this.initGetWindow()
    }
    componentWillUnmount() {}
    async getTicket() {
      try {
        const { body: a } = await g({
          url: `${f.getDataOpenTicket}?appid=${this.props.appid}`,
          needToken: 1
        })
        console.log('res', a), this.setState({ open_ticket: a.open_ticket })
      } catch (a) {
        console.info(`custom-analysis init error: ${a}`),
          this.props.closeCustomAnalysis()
      }
    }
    async initGetWindow() {
      this.win = await d.onWindowRegistered('custom_analysis')
      const a = this.win.window.navigator.userAgent
      Object.defineProperty(this.win.window.navigator, 'userAgent', {
        get: () => `${a} devtools`
      }),
        console.log('init popup done'),
        this.win.showDevTools()
    }
    onMessage(a) {
      'Object' === k(a.data) &&
        'GET_APP_CONFIG' === a.data.type &&
        (console.info('custom analysis get', a.data),
        this.props.updateCustomAnalysisConfig(
          JSON.stringify(a.data.config || [])
        ),
        i.triggerOnEvent({
          eventName: 'onAppConfig',
          data: { data: a.data.config, type: 1 }
        }))
    }
    onWindowClose() {
      this.props.closeCustomAnalysis()
    }
    render() {
      return this.state.open_ticket
        ? a.createElement(c, {
            width: 1200,
            height: global.Win.height,
            registryId: 'custom_analysis',
            url: `https://mp.weixin.qq.com/wxopen/userdefineanalysis_ide?action=event_list&dev_code=${
              this.state.open_ticket
            }&appid=${this.props.appid}&devtools=1`,
            onMessage: this.onMessage.bind(this),
            onWindowClose: this.onWindowClose.bind(this)
          })
        : null
    }
  }
  module.exports = l
})(require('lazyload'), require)
