'use strict'
!(function(require, directRequire) {
  async function a() {
    const a = global.windowMap.get('MAIN').window
    let b = document.createElement('input')
    return (
      (b.style.display = 'none'),
      b.setAttribute('type', 'file'),
      b.setAttribute('accept', 'image/*'),
      a.document.body.appendChild(b),
      b.click(),
      new Promise(c => {
        b.addEventListener('change', () => {
          a.document.body.removeChild(b), c({ success: !0, filePath: b.value })
        }),
          b.addEventListener('cancel', () => {
            a.document.body.removeChild(b), c({ success: !1 })
          })
      })
    )
  }
  const b = require('fs'),
    c = require('react'),
    d = require('redux'),
    e = require('./fc137838572a83604db39acff8e909e0.js'),
    f = require('./eadce02c750c875a10680bcfedadec88.js'),
    g = require('./a8c87029da0fa06e986298d447ab0fe2.js'),
    h = require('./1fcc6bd55b687d154a4247e57fe3011d.js'),
    i = require('./ba23d8b47b1f4ea08b9fd49939b9443f.js'),
    j = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    k = require('./cc2c2970ff81ae4a83123e81ee123da2.js'),
    l = require('./9fdd4ac31a05c27355910f0d74accd4c.js'),
    m = require('./3b5f8e2469c474c8d433c1c6926d8999.js'),
    n = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    o = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    p = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    q = require('url'),
    r = require('querystring'),
    { connect: s } = require('react-redux')
  class t extends c.Component {
    onAddCustomCompile() {
      this.props.setCustomCompile({ show: this.props.compileType, id: -1 }),
        this.props.toggleClickKey(f.NONE)
    }
    onSelect(a) {
      this.props.selectCompileCondiction(a)
    }
    onEditItemClick(a, b) {
      b.stopPropagation(),
        this.props.setCustomCompile({ show: this.props.compileType, id: a }),
        this.props.toggleClickKey(f.NONE)
    }
    async onQrcodeCompile() {
      let c = await a()
      if (c.success) {
        let a = c.filePath
        p({
          url: `${n.jsDecodeQRCodeURL}`,
          method: 'post',
          body: b.readFileSync(a),
          needToken: 1,
          needAppID: 1
        })
          .then(a => {
            let b = a.body
            if (b.result || b.path) {
              let a = b.path ? decodeURIComponent(b.path) : ''
              if (b.is_self_wxa) {
                let b = q.parse(a),
                  c = r.parse(b.query || '', null, null, {
                    decodeURIComponent: a => {
                      return a
                    }
                  })
                return this.props.compile({
                  origin: o.COMPILE_ORIGIN.BUTTON,
                  condiction: {
                    pathName: (b.pathname || '').replace(/\.html$/, ''),
                    scene: 1011,
                    query: c
                  }
                })
              }
              if (!1 === b.is_self_wxa)
                return this.props.showError(
                  `解析二维码失败：非本 AppID 的小程序码`
                )
              if (
                0 ==
                b.result.indexOf('https://open.weixin.qq.com/sns/getexpappinfo')
              ) {
                let a = q.parse(b.result),
                  c = r.parse(a.query)
                return c.appid == this.props.project.appid
                  ? ((a = q.parse(c.path || '')),
                    (c = r.parse(a.query || '', null, null, {
                      decodeURIComponent: a => {
                        return a
                      }
                    })),
                    this.props.compile({
                      origin: o.COMPILE_ORIGIN.BUTTON,
                      condiction: {
                        pathName: (a.pathname || '').replace(/\.html$/, ''),
                        scene: 1011,
                        query: c
                      }
                    }))
                  : void this.props.showError(
                      `解析二维码失败：非本 AppID 的小程序码`
                    )
              }
              return this.props.showError(`解析二维码失败：非小程序码`)
            }
            return this.props.showError(`解析二维码失败`)
          })
          .catch(a => {
            this.props.showError(`解析二维码失败：${a}`)
          })
      }
    }
    render() {
      let a = this.props,
        b = a.list.map((b, d) => {
          return c.createElement(
            'div',
            {
              className: 'ui-dropdown-item',
              key: d,
              onClick: this.onSelect.bind(this, d)
            },
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-hd' },
              a.current == d
                ? c.createElement('i', { className: 'ui-icon-tick' })
                : null
            ),
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-bd' },
              c.createElement('span', null, b.name)
            ),
            c.createElement(
              'div',
              {
                className: 'ui-dropdown-item-ft',
                onClick: this.onEditItemClick.bind(this, d)
              },
              c.createElement(
                'span',
                { className: 'ui-dropdown-opr' },
                c.createElement('i', { className: 'ui-icon-pencil' })
              )
            )
          )
        })
      return c.createElement(
        'div',
        {
          className: 'ui-popover',
          style: {
            top: this.props.top,
            left: this.props.left,
            display: a.show ? '' : 'none'
          }
        },
        c.createElement(
          'div',
          { className: 'ui-dropdown' },
          c.createElement(
            'div',
            {
              className: 'ui-dropdown-item',
              onClick: this.onSelect.bind(this, -1)
            },
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-hd' },
              -1 == a.current
                ? c.createElement('i', { className: 'ui-icon-tick' })
                : null
            ),
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-bd' },
              c.createElement('span', null, '\u666E\u901A\u7F16\u8BD1')
            )
          ),
          c.createElement('div', { className: 'ui-dropdown-divider' }),
          c.createElement(
            'div',
            { style: { maxHeight: '300px', overflowY: 'auto' } },
            b
          ),
          c.createElement('div', {
            className: 'ui-dropdown-divider',
            style: b && 0 < b.length ? {} : m.displayNone
          }),
          c.createElement(
            'div',
            {
              className: 'ui-dropdown-item',
              onClick: this.onAddCustomCompile.bind(this)
            },
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-hd' },
              c.createElement('i', { className: 'ui-icon-plus' })
            ),
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-bd' },
              c.createElement(
                'span',
                null,
                '\u6DFB\u52A0\u7F16\u8BD1\u6A21\u5F0F'
              )
            )
          ),
          c.createElement(
            'div',
            {
              className: 'ui-dropdown-item',
              onClick: this.onQrcodeCompile.bind(this)
            },
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-hd' },
              c.createElement('i', { className: 'ui-icon-qrcode' })
            ),
            c.createElement(
              'div',
              { className: 'ui-dropdown-item-bd' },
              c.createElement(
                'span',
                null,
                '\u901A\u8FC7\u4E8C\u7EF4\u7801\u7F16\u8BD1'
              )
            )
          )
        )
      )
    }
  }
  module.exports = s(
    a => {
      let b = a.toolbar.clickKey == f.COMPILECONDICTION,
        c = a.project.current || {},
        d = c.compileType,
        e = (c.condiction && c.condiction[d]) || {},
        g = e.current,
        h = e.list || []
      return { compileType: d, show: b, current: g, list: h, project: c }
    },
    a => {
      return {
        toggleClickKey: j.bindActionCreators(e.toggleClickKey, a),
        setCustomCompile: j.bindActionCreators(g.setCustomCompile, a),
        selectCompileCondiction: j.bindActionCreators(
          k.selectCompileCondiction,
          a
        ),
        showError: j.bindActionCreators(h.showError, a),
        compile: j.bindActionCreators(i.compileImmediate, a)
      }
    }
  )(t)
})(require('lazyload'), require)
