'use strict'
!(function(require, directRequire) {
  const a = require('./c016c015550b8c8e4a79e8e85062bd17.js'),
    b = require('./76d9df7b0b3e47fbe17881420a4bef86.js'),
    c = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    d = require('./ff946754202ecf377034d29daac7c8d9.js'),
    e = require('./a7261ee5e1a26dddf8d07b048ad1c94d.js'),
    f = (a, b, c, e) => {
      return new Promise(f => {
        const g = h => {
          h = JSON.parse(h)
          const { command: i, data: j } = h
          i == b &&
            j.callbackID == c &&
            (d.off(`WEBVIEW_${a}`, g), f(j.res), 'function' == typeof e && e())
        }
        d.on(`WEBVIEW_${a}`, g)
      })
    }
  module.exports = {
    [a.Name.FIND_WEBVIEW]: async (a, d) => {
      const e = d.route,
        f = c.getState()
      let g = null
      for (let b in f.simulator.webviewInfos) {
        let a = f.simulator.webviewInfos[b]
        a.pathName == e && (g = b)
      }
      return g
        ? { status: b.Success, value: { WEBVIEW: g } }
        : { status: b.InvalidElementState }
    },
    [a.Name.FIND_WEBVIEW_ELEMENT]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.findElement',
              data: { callbackID: h, value: e.value, using: e.using }
            })
          ),
          f(g, 'Driver.findElement.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.FIND_WEBVIEW_ELEMENTS]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.findElements',
              data: { callbackID: h, value: e.value, using: e.using }
            })
          ),
          f(g, 'Driver.findElements.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.TOUCH_CLICK_WEBVIEW_ELEMENT]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        h = e.element,
        i = `${Math.random()}${Date.now()}`,
        j = c.getState()
      return j.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.tapElement',
              data: { callbackID: i, ELEMENT: h }
            })
          ),
          f(g, 'Driver.tapElement.callback', i))
        : { status: b.NoSuchFrame }
    },
    [a.Name.TOUCH_LONGCLICK_WEBVIEW_ELEMENT]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        h = e.element,
        i = `${Math.random()}${Date.now()}`,
        j = c.getState()
      return j.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.longtapElement',
              data: { callbackID: i, ELEMENT: h }
            })
          ),
          f(g, 'Driver.longtapElement.callback', i))
        : { status: b.NoSuchFrame }
    },
    [a.Name.TOUCH_DOWN_WEBVIEW]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        { x: h, y: i } = e,
        j = `${Math.random()}${Date.now()}`,
        k = c.getState()
      return k.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.touchDown',
              data: { callbackID: j, x: h, y: i }
            })
          ),
          f(g, 'Driver.touchDown.callback', j))
        : { status: b.NoSuchFrame }
    },
    [a.Name.TOUCH_MOVE_WEBVIEW]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        { x: h, y: i } = e,
        j = `${Math.random()}${Date.now()}`,
        k = c.getState()
      return k.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.touchMove',
              data: { callbackID: j, x: h, y: i }
            })
          ),
          f(g, 'Driver.touchMove.callback', j))
        : { status: b.NoSuchFrame }
    },
    [a.Name.TOUCH_UP_WEBVIEW]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        { x: h, y: i } = e,
        j = `${Math.random()}${Date.now()}`,
        k = c.getState()
      return k.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.touchUp',
              data: { callbackID: j, x: h, y: i }
            })
          ),
          f(g, 'Driver.touchUp.callback', j))
        : { status: b.NoSuchFrame }
    },
    [a.Name.TOUCH_SCROLL_WEBVIEW]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        { xoffset: h, yoffset: i } = e,
        j = `${Math.random()}${Date.now()}`,
        k = c.getState()
      return k.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.scroll',
              data: { callbackID: j, xoffset: h, yoffset: i }
            })
          ),
          f(g, 'Driver.scroll.callback', j))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_APPSERVICE_DATA]: async () => {
      return new Promise(a => {
        const c = e => {
          e = JSON.parse(e)
          const { command: f, data: g } = e
          'SEND_APP_DATA' == f &&
            (d.off('APPSERVICE', c), a({ status: b.Success, value: g }))
        }
        d.on('APPSERVICE', c),
          d.sendMessage(
            'APPSERVICE',
            JSON.stringify({ command: 'GET_APP_DATA' })
          )
      })
    },
    [a.Name.SEND_KEYS_TO_WEBVIEW_ELEMENT]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        h = a.getParameter('id'),
        i = `${Math.random()}${Date.now()}`,
        j = c.getState()
      if (!j.simulator.webviewInfos[g]) return { status: b.NoSuchFrame }
      let k = global.windowMap.get('MAIN').window.document,
        l = j.simulator.webviewInfos[g].pathName,
        m = k.querySelector(`[route="${l}"]`)
      return (
        m.focus(),
        d.sendMessage(
          `WEBVIEW_${g}`,
          JSON.stringify({
            command: 'Driver.sendKeys',
            data: { callbackID: i, ELEMENT: h, value: e.value }
          })
        ),
        f(g, 'Driver.sendKeys.callback', i, () => {
          m.blur()
        })
      )
    },
    [a.Name.GET_WEBVIEW_ELEMENT_TAG_NAME]: async a => {
      const e = a.getParameter('webviewId'),
        g = a.getParameter('id'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[e]
        ? (d.sendMessage(
            `WEBVIEW_${e}`,
            JSON.stringify({
              command: 'Driver.getTagName',
              data: { callbackID: h, ELEMENT: g }
            })
          ),
          f(e, 'Driver.getTagName.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_WEBVIEW_ELEMENT_ATTRIBUTE]: async a => {
      const e = a.getParameter('webviewId'),
        g = a.getParameter('id'),
        h = a.getParameter('name'),
        i = `${Math.random()}${Date.now()}`,
        j = c.getState()
      return j.simulator.webviewInfos[e]
        ? (d.sendMessage(
            `WEBVIEW_${e}`,
            JSON.stringify({
              command: 'Driver.getAttribute',
              data: { callbackID: i, ELEMENT: g, name: h }
            })
          ),
          f(e, 'Driver.getAttribute.callback', i))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_WEBVIEW_ELEMENT_LOCATION]: async a => {
      const e = a.getParameter('webviewId'),
        g = a.getParameter('id'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[e]
        ? (d.sendMessage(
            `WEBVIEW_${e}`,
            JSON.stringify({
              command: 'Driver.getLocation',
              data: { callbackID: h, ELEMENT: g }
            })
          ),
          f(e, 'Driver.getLocation.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_WEBVIEW_ELEMENT_SIZE]: async a => {
      const e = a.getParameter('webviewId'),
        g = a.getParameter('id'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[e]
        ? (d.sendMessage(
            `WEBVIEW_${e}`,
            JSON.stringify({
              command: 'Driver.getSize',
              data: { callbackID: h, ELEMENT: g }
            })
          ),
          f(e, 'Driver.getSize.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_WEBVIEW_ELEMENT_RECT]: async a => {
      const e = a.getParameter('webviewId'),
        g = a.getParameter('id'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[e]
        ? (d.sendMessage(
            `WEBVIEW_${e}`,
            JSON.stringify({
              command: 'Driver.getRect',
              data: { callbackID: h, ELEMENT: g }
            })
          ),
          f(e, 'Driver.getRect.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_WEBVIEW_ELEMENT_VALUE_OF_CSS_PROPERTY]: async a => {
      const e = a.getParameter('webviewId'),
        g = a.getParameter('id'),
        h = a.getParameter('propertyName'),
        i = `${Math.random()}${Date.now()}`,
        j = c.getState()
      return j.simulator.webviewInfos[e]
        ? (d.sendMessage(
            `WEBVIEW_${e}`,
            JSON.stringify({
              command: 'Driver.getCssValue',
              data: { callbackID: i, ELEMENT: g, propertyName: h }
            })
          ),
          f(e, 'Driver.getCssValue.callback', i))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_CURRENT_HTML]: async () =>
      new Promise(async (a, d) => {
        try {
          const d = c.getState(),
            f = await e.getCurrentHTML(),
            g = d.project.current.appid,
            h =
              (d.simulator.webviewInfos &&
                d.simulator.webviewInfos[d.simulator.currentWebviewID]) ||
              {},
            i = h.pathName || ''
          a({ status: b.Success, value: f, extend: { appid: g, route: i } })
        } catch (a) {
          d({ status: b.JavaScriptError })
        }
      }),
    [a.Name.GET_SCREENSHOT]: async () =>
      new Promise(async (a, d) => {
        try {
          const d = c.getState(),
            f = await e.getScreenShot(),
            g = d.project.current.appid,
            h =
              (d.simulator.webviewInfos &&
                d.simulator.webviewInfos[d.simulator.currentWebviewID]) ||
              {},
            i = h.pathName || ''
          a({ status: b.Success, value: f, extend: { appid: g, route: i } })
        } catch (a) {
          d({ status: b.JavaScriptError })
        }
      }),
    [a.Name.GET_CURRENT_PAGE_STACK]: async () =>
      new Promise(async (a, c) => {
        try {
          const c = await e.getCurrentPageStack()
          a({ status: b.Success, value: c })
        } catch (a) {
          c({ status: b.JavaScriptError })
        }
      }),
    [a.Name.GET_CURRENT_PAGE_TITLE]: async () =>
      new Promise(async (a, c) => {
        try {
          const c = await e.getCurrentPageTitle()
          a({ status: b.Success, value: c })
        } catch (a) {
          c({ status: b.JavaScriptError })
        }
      }),
    [a.Name.GET_CURRENT_PAGE_QUERY]: async () =>
      new Promise(async (a, c) => {
        try {
          const c = await e.getCurrentPageQuery()
          a({ status: b.Success, value: c })
        } catch (a) {
          c({ status: b.JavaScriptError })
        }
      }),
    [a.Name.FIND_WEBVIEW_ELEMENT_FROM_POINT]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.elementFromPoint',
              data: { callbackID: h, x: e.x, y: e.y }
            })
          ),
          f(g, 'Driver.elementFromPoint.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.FIND_WEBVIEW_ACTION_ELEMENT_FROM_POINT]: async (a, e) => {
      const g = a.getParameter('webviewId'),
        h = `${Math.random()}${Date.now()}`,
        i = c.getState()
      return i.simulator.webviewInfos[g]
        ? (d.sendMessage(
            `WEBVIEW_${g}`,
            JSON.stringify({
              command: 'Driver.actionElementFromPoint',
              data: { callbackID: h, x: e.x, y: e.y }
            })
          ),
          f(g, 'Driver.actionElementFromPoint.callback', h))
        : { status: b.NoSuchFrame }
    },
    [a.Name.GET_WEBVIEW_CONTENT_SIZE]: async a => {
      const e = a.getParameter('webviewId'),
        g = `${Math.random()}${Date.now()}`,
        h = c.getState()
      return h.simulator.webviewInfos[e]
        ? (d.sendMessage(
            `WEBVIEW_${e}`,
            JSON.stringify({
              command: 'Driver.getContentSize',
              data: { callbackID: g }
            })
          ),
          f(e, 'Driver.getContentSize.callback', g))
        : { status: b.NoSuchFrame }
    }
  }
})(require('lazyload'), require)
