'use strict'
!(function(require, directRequire) {
  function a(a, b) {
    return Math.floor(Math.random() * (b - a + 1)) + a
  }
  function b() {
    const a = h.getState()
    let b = a.simulator || {},
      c = ((a.project || {}).current || {}).attr,
      d =
        ((c || {}).setting || {}).ExpendedMaxWebviewDepth ||
        f.MAX_PAGE_STACK_DEPTH,
      e = b.webviewInfos || {},
      g = 0,
      i = !1
    for (let a in e)
      i || -1 != e[a].parent || ((i = !0), g++), -1 != e[a].parent && g++
    return g < d
  }
  function c(a) {
    const b = h.getState(),
      c = h.dispatch.bind(h)
    let d = g.checkIsInSubPackage(b.simulator.appConfig, a)
    d &&
      c({
        type: e.SIMULATOR_LOAD_SUBPACKAGE,
        data: { root: d.root, loaded: !1 }
      })
  }
  function d(a) {
    const b = h.getState()
    let c = -1,
      d = `${a}.html`
    try {
      c = b.simulator.appConfig.tabBar.list.findIndex(a => {
        return a.pagePath && a.pagePath == d
      })
    } catch (a) {
      c = -1
    }
    return c
  }
  const e = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    f = require('./6242f55dbdfe53c2f07b7a51568311f2.js'),
    g = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    h = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js')
  module.exports = {
    navigateTo: async function(a, f) {
      if (!b()) return { errMsg: `${f.api}:fail webview count limit exceed` }
      let { pathName: h, query: i } = g.parseUrl(f.args.url)
      return 0 <= d(h)
        ? { errMsg: `${f.api}:fail can not navigateTo a tabbar page` }
        : (a({ type: e.SIMULATOR_NAVIGATE, data: { pathName: h, query: i } }),
          c(h),
          { errMsg: `${f.api}:ok` })
    },
    navigateBack: async function(a, b) {
      return (
        a({ type: e.SIMULATOR_NAVIGATE_BACK, delta: b.args.delta || 1 }),
        { errMsg: `${b.api}:ok` }
      )
    },
    redirectTo: async function(a, b) {
      let { pathName: f, query: h } = g.parseUrl(b.args.url)
      return 0 <= d(f)
        ? { errMsg: `${b.api}:fail can not redirectTo a tabbar page` }
        : (a({ type: e.SIMULATOR_REDIRECT, data: { pathName: f, query: h } }),
          c(f),
          { errMsg: `${b.api}:ok` })
    },
    switchTab: async function(a, b) {
      let { pathName: f } = g.parseUrl(b.args.url),
        h = d(f)
      return -1 == h
        ? { errMsg: `${b.api}:fail can not switch to no-tabBar page` }
        : (a({
            type: e.SIMULATOR_OPEN_TABBAR,
            data: { query: {}, pathName: f, tabbarIndex: h }
          }),
          c(f),
          { errMsg: `${b.api}:ok` })
    },
    reLaunch: async function(a, b) {
      let { pathName: d, query: f } = g.parseUrl(b.args.url)
      return (
        a({ type: e.SIMULATOR_RELAUNCH, data: { pathName: d, query: f } }),
        c(d),
        { errMsg: `${b.api}:ok` }
      )
    },
    updateApp: async function(b, c) {
      return (
        b({
          type: e.SIMULATOR_SET_TOAST,
          data: {
            show: !0,
            icon: 'loading',
            title: '\u5E94\u7528\u91CD\u542F\u4E2D',
            mask: !0
          }
        }),
        setTimeout(() => {
          b({ type: e.SIMULATOR_COMPILE, data: {} })
        }, a(1e3, 5e3)),
        { errMsg: `${c.api}:ok` }
      )
    },
    openUrl: async function(a, b) {
      const c = h.getState()
      if (c.simulator.anyHtmlWebviewInfo)
        return {
          errMsg: `${
            b.api
          }:fail could not open unless the previous webpage is closed`
        }
      for (const d in c.simulator.webviewInfos) {
        const a = c.simulator.webviewInfos[d]
        if (a.htmlwebviewInfo)
          return { errMsg: `${b.api}:fail could not open in a web-view page` }
      }
      return (
        a({
          type: e.SIMULATOR_SET_ANY_HTMLWEBVIEW,
          data: { url: b.args.url, webviewID: +new Date() }
        }),
        { errMsg: `${b.api}:ok` }
      )
    }
  }
})(require('lazyload'), require)
