'use strict'
!(function(require, directRequire) {
  function a(a, b = {}) {
    try {
      let { webviewID: c, url: d, isFromSdkUpdate: e, redirectFromUrl: f } = b
      const g = a.simulator.webviewInfos[c]
      if (!g || !g.htmlwebviewInfo) return !0
      let h = g.htmlwebviewInfo
      if (e && h.originUrl != d) return !1
      if (f && h.originUrl != f) return !1
    } catch (a) {}
    return !0
  }
  const b = require('./822bc5aa1823c9aa222d9ffad72e7f17.js'),
    c = require('./f0b1e76146041102932a0ff6c1247619.js'),
    d = require('./df6d0ff021a69fb541c733de4dbba0fe.js'),
    e = require('./common/locales/index.js'),
    f = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    g = require('./0b01a3ff1572567a994a0ceae64dfef3.js'),
    h = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    i = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    j = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    k = require('./2dfc6a3df6d6fc51266b293c8420e88b.js'),
    l = require('url'),
    m = require('querystring')
  module.exports = {
    showDevtools: function(a) {
      return { type: b.WEBDEBUGGER_SHOW_DEVTOOLS, webview: a }
    },
    setUrl: function(a) {
      return { type: b.WEBDEBUGGER_SET_URL, url: a }
    },
    getA8Key: function(a) {
      return f => {
        c(a)
          .then(c => {
            let g = c.baseresponse || {},
              h = g.errcode
            if (h == d.NOT_LIMITS || h == d.NOT_LIMITS_QY) {
              let a = j.parseCgiErrorCode(h, g.errmsg)
              return void (
                global.autoTest ||
                f({
                  type: b.WEBDEBUGGER_SET_CONFIRM,
                  data: {
                    show: !0,
                    confirmText: '\u67E5\u770B\u6587\u6863',
                    content: a,
                    callback: a => {
                      a &&
                        nw.Shell.openExternal(
                          'https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455784140'
                        )
                    }
                  }
                })
              )
            }
            if (0 !== h) {
              let a = j.parseCgiErrorCode(h, g.errmsg)
              return void f({
                type: b.WEBDEBUGGER_SET_CONFIRM,
                data: {
                  show: !0,
                  confirmText: '\u51FA\u73B0\u9519\u8BEF',
                  content: a
                }
              })
            }
            f({
              type: b.WEBDEBUGGER_SET_PURVIEW,
              data: {
                lastGetA8KeyUrl: a.url,
                purviewFormGetA8key: c.purviewFormGetA8key
              }
            })
            let i = c.resp_url
            if (a.isSync || c.force_redirect || h == d.ILLEGAL_URL)
              return (
                f({ type: b.WEBDEBUGGER_SET_URL, url: i, from: a.from }),
                void f({ type: b.WEBDEBUGGER_SET_ACT, data: 'load' })
              )
            let k = /\#wechat_redirect$/.test(a.url)
            if (k && a.url.replace(/\#wechat_redirect$/, '') === i)
              return (
                (i = i.replace(/\#wechat_redirect/, '')),
                void f({
                  type: b.WEBDEBUGGER_SET_CONFIRM,
                  data: {
                    show: !0,
                    showCancel: !1,
                    content: e.config.CGI_ERR_OAUTH_NOT_SUPPORT
                  }
                })
              )
          })
          .catch(a => {
            f({
              type: b.WEBDEBUGGER_SET_CONFIRM,
              data: { show: !0, showCancel: !1, content: a }
            })
          })
      }
    },
    setAutoComplete: function(a) {
      return { type: b.WEBDEBUGGER_SET_AUTOCOMPLETE, url: a }
    },
    setActions: function(a) {
      return { type: b.WEBDEBUGGER_SET_ACT, data: a }
    },
    setFooter: function(a) {
      return { type: b.WEBDEBUGGER_SET_FOOTER, data: a }
    },
    setShare: function(a) {
      return { type: b.WEBDEBUGGER_SET_SHARE, data: a }
    },
    setJssdkCallback: function(a) {
      return { type: b.WEBDEBUGGER_SET_JSSDKCALLBACK, data: a }
    },
    hideCardView: function({ callbackID: a, res: c, runtimeID: d }) {
      return e => {
        e({
          type: b.WEBDEBUGGER_SET_CARD_VIEW,
          data: { show: 'none', cardInfo: [] }
        }),
          a &&
            e({
              type: b.WEBDEBUGGER_SET_JSSDKCALLBACK,
              data: { callbackID: a, runtimeID: d, res: c }
            })
      }
    },
    batchAddCard: function({ callbackID: a, list: c, runtimeID: d }) {
      return e => {
        const h = i.getState(),
          j = h.webdebugger || {},
          k = j.cardInfo || {},
          l = k.appid
        let m = {
          url: `${g.batchAddCardURL}?isapp=1`,
          body: JSON.stringify({ appid: l, acceptitem_list: c }),
          method: 'post',
          needToken: 1
        }
        f(m)
          .then(f => {
            let g = f.body,
              h = g.resp_list
            ;(h = h.map((a, b) => {
              let d = c[b],
                e = JSON.parse(a.json_ret)
              return {
                cardId: d.card_id,
                cardExt: d.card_ext,
                code: e.encrypt_code,
                isSuccess: !0
              }
            })),
              e({
                type: b.WEBDEBUGGER_SET_JSSDKCALLBACK,
                data: {
                  callbackID: a,
                  runtimeID: d,
                  res: { errMsg: `addCard:ok`, cardList: h }
                }
              })
          })
          .catch(c => {
            e({
              type: b.WEBDEBUGGER_SET_JSSDKCALLBACK,
              data: {
                callbackID: a,
                runtimeID: d,
                res: { errMsg: `addCard:fail ${c}` }
              }
            })
          }),
          e({
            type: b.WEBDEBUGGER_SET_CARD_VIEW,
            data: { show: 'none', cardInfo: [] }
          })
      }
    },
    clearAutoComplete: function() {
      return { type: b.WEBDEBUGGER_CLEAR_AUTOCOMPLETE }
    },
    setClickkey: function(a) {
      return c => {
        c({ type: b.TOOLBAR_TOGGLE_CLICKKEY, clickKey: a }),
          c({ type: b.WEBDEBUGGER_SET_CLICKKEY, data: a })
      }
    },
    setLeftBtn: function(a) {
      return { type: b.WEBDEBUGGER_SET_LEFTBTN, data: a }
    },
    setTitle: function(a) {
      return { type: b.WEBDEBUGGER_SET_TITLE, data: a }
    },
    setUrlComplete: function(a) {
      return { type: b.WEBDEBUGGER_SET_URLCOMPLETE, data: a }
    },
    setConfirm: function(a) {
      return { type: b.WEBDEBUGGER_SET_CONFIRM, data: a }
    },
    getWeappA8Key: function(f) {
      return (g, i) => {
        const n = i(),
          o = (n.project.current || { setting: { urlCheck: !0 } }).setting
            .urlCheck,
          p = /^https:\/\/open\.weixin\.qq\.com\/connect\/oauth2/.test(f.url)
        if (!o && !p) {
          k.display({
            command: h.DISPLAY_INFO,
            type: h.DISPLAY_TYPES.HINT_NO_URL_CHECK
          }),
            g({
              type: b.WEBDEBUGGER_SET_PURVIEW,
              data: { lastGetA8KeyUrl: f.url, purviewFormGetA8key: {} }
            })
          let a = f.url
          if (f.isSync)
            return (
              g({ type: b.WEBDEBUGGER_SET_URL, url: a }),
              void g({
                type: b.SIMULATOR_UPDATE_HTMLWEBVIEW,
                data: {
                  htmlId: f.htmlId,
                  webviewID: f.webviewID,
                  forceRedirect: 0,
                  src: a
                }
              })
            )
          let c = /\#wechat_redirect$/.test(f.url)
          return c && f.url.replace(/\#wechat_redirect$/, '') === a
            ? ((a = a.replace(/\#wechat_redirect/, '')),
              void g({
                type: b.INFO_SET_CONFIRM,
                data: {
                  show: !0,
                  showCancel: !1,
                  content: e.config.CGI_ERR_OAUTH_NOT_SUPPORT
                }
              }))
            : void 0
        }
        ;(f.isWeapp = !0),
          c(f)
            .then(c => {
              let h = c.baseresponse || {},
                k = h.errcode,
                n = i()
              if (!a(n, f)) return
              if (k == d.NOT_LIMITS || k == d.NOT_LIMITS_QY) {
                let a = j.parseCgiErrorCode(k, h.errmsg),
                  c = f.url
                if (p) {
                  let b = l.parse(c),
                    d = m.parse(b.query)
                  ;(c = d.redirect_uri), c && (a = `${a}, url:${c}`)
                }
                return void (
                  global.autoTest ||
                  g({
                    type: b.INFO_SET_CONFIRM,
                    data: {
                      show: !0,
                      confirmText: '\u67E5\u770B\u6587\u6863',
                      content: `${a}`,
                      callback: a => {
                        a &&
                          nw.Shell.openExternal(
                            'https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455784140'
                          )
                      }
                    }
                  })
                )
              }
              g({
                type: b.WEBDEBUGGER_SET_PURVIEW,
                data: {
                  lastGetA8KeyUrl: f.url,
                  purviewFormGetA8key: c.purviewFormGetA8key
                }
              })
              let o = c.resp_url
              if (f.isSync || c.force_redirect || k == d.ILLEGAL_URL)
                return (
                  g({ type: b.WEBDEBUGGER_SET_URL, url: o }),
                  void g({
                    type: b.SIMULATOR_UPDATE_HTMLWEBVIEW,
                    data: {
                      htmlId: f.htmlId,
                      webviewID: f.webviewID,
                      forceRedirect: c.force_redirect || k == d.ILLEGAL_URL,
                      src: o
                    }
                  })
                )
              let q = /\#wechat_redirect$/.test(f.url)
              if (q && f.url.replace(/\#wechat_redirect$/, '') === o)
                return (
                  (o = o.replace(/\#wechat_redirect/, '')),
                  void g({
                    type: b.INFO_SET_CONFIRM,
                    data: {
                      show: !0,
                      showCancel: !1,
                      content: e.config.CGI_ERR_OAUTH_NOT_SUPPORT
                    }
                  })
                )
            })
            .catch(a => {
              g({
                type: b.INFO_SET_CONFIRM,
                data: { show: !0, showCancel: !1, content: a }
              })
            })
      }
    }
  }
})(require('lazyload'), require)
