'use strict'
!(function(require, directRequire) {
  const a = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    b = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    c = b.dispatch.bind(b),
    d = require('querystring')
  const e = new class {
    constructor() {
      ;(this.map = new Map()), (this._id = 0)
    }
    getNextID() {
      return ++this._id
    }
    serialize(a) {
      const b = this.getNextID()
      return this.map.set(b, a), b
    }
    deserialize(a) {
      return this.map.get(a)
    }
  }()
  module.exports = {
    invokeCallback: a => {
      try {
        if (a.callbackID) {
          const b = e.deserialize(a.callbackID)
          b && b(a.data)
        }
      } catch (a) {}
    },
    getCurrentHTML: () =>
      new Promise(async (d, f) => {
        try {
          const f = b.getState(),
            g = f.simulator.currentWebviewID
          c({
            type: a.SIMULATOR_CALL_INTERFACE,
            callbackID: e.serialize(d),
            method: 'getWebviewHTML',
            data: { webviewID: g }
          })
        } catch (a) {
          f(a)
        }
      }),
    getScreenShot: () =>
      new Promise(async (d, f) => {
        try {
          if (global.online)
            return void global.Win.capturePage(
              a => {
                global.Win.setAlwaysOnTop(!1), d(a)
              },
              { format: 'png', datatype: 'datauri' }
            )
          const f = b.getState(),
            g = f.simulator.currentWebviewID
          c({
            type: a.SIMULATOR_CALL_INTERFACE,
            callbackID: e.serialize(d),
            method: 'getScreenShot',
            data: { webviewID: g }
          })
        } catch (a) {
          f(a)
        }
      }),
    getCurrentPageStack: () =>
      new Promise((a, c) => {
        try {
          const c = b.getState(),
            d = c.simulator,
            e = d.currentWebviewID,
            f = d.webviewInfos
          let g = f[e]
          if (!g) return a([])
          let h = 20
          const i = [g.pathName]
          for (
            ;
            -1 != g.parent &&
            ((g = f[g.parent]), i.unshift(g.pathName), !(0 >= --h));

          );
          a(i)
        } catch (a) {
          c(a)
        }
      }),
    getCurrentPageTitle: () =>
      new Promise((a, c) => {
        try {
          const c = b.getState(),
            d = c.simulator,
            e = d.currentWebviewID,
            f = d.webviewInfos
          let g = f[e]
          if (!g) return a('')
          a(g.navigationBar.title)
        } catch (a) {
          c(a)
        }
      }),
    getCurrentPageQuery: () =>
      new Promise((a, c) => {
        try {
          const c = b.getState(),
            e = c.simulator,
            f = e.currentWebviewID,
            g = e.webviewInfos
          let h = g[f]
          if (!h) return a('')
          a(d.stringify(h.query || {}))
        } catch (a) {
          c(a)
        }
      })
  }
})(require('lazyload'), require)
