'use strict'
!(function(require, directRequire) {
  function a() {
    o = void 0
  }
  function b() {
    a()
  }
  async function c(c) {
    let d = await e(c)
    ;(p && p.srcPath == d.srcPath) ||
      (a(), p && p.unWatch(b), (p = d), p.watch(b)),
      q && q.es6 != c.setting.es6 && a(),
      (q = c.setting)
  }
  const d = require('source-map'),
    e = require('./a63026ab5a5a3c59a61a9749a18aa2ca.js'),
    f = require('./a89be4febc57a81e9865a060f74e14c8.js'),
    g = require('./e53dfc2b83456f986002c49964f30fbf.js'),
    h = require('./80a27260d67a4c5a94011a75ea778fcb.js'),
    i = require('./6e1614a32b5d10964071477dd7310d21.js'),
    j = require('./2d8c17f8789be1869edbd369314f5eaa.js'),
    k = require('./503c215d003cb9646f16deee95253baf.js'),
    { NO_BOM_VAR: l } = require('./6242f55dbdfe53c2f07b7a51568311f2.js'),
    m = require('./logger.js'),
    n = [
      'define',
      'require',
      'module',
      'exports',
      'global',
      'wx',
      'App',
      'Page',
      'Component',
      'Behavior',
      'getApp',
      'getCurrentPages'
    ]
  var o, p, q
  const r = async (a, b = {}) => {
    const { pluginId: c, version: e } = b
    let j = [],
      o = [],
      q = new d.SourceMapGenerator({ file: `${c}.js` }),
      r = 0
    o.push(`definePlugin("plugin://${c}", function(${n.join(',')}) {`),
      o.push('var __wxAppCode__ = global.__wxAppCode__'),
      j.push(o.join(';')),
      r++
    let s = await i(a, { cut: !0, pluginId: c, version: e })
    j.push(`${s.code}`), (r += s.code.split('\n').length)
    let t = await k(a, { wxss: !1, prefix: s.name, pluginId: c, version: e })
    j.push(t.join(';')), r++
    let u = p.getAllJSFiles(),
      v = {}
    for (let c, e = 0, f = u.length; e < f; e++) {
      if (((c = u[e]), v[c])) continue
      v[c] = !0
      let b = await h(a, c)
      if (
        (j.push(`define("${c}", function(require, module, exports, ${l}){`),
        r++,
        j.push(b.code),
        b.map)
      )
        try {
          let a = new d.SourceMapConsumer(b.map)
          q.setSourceContent(c, a.sourcesContent[0]),
            a.eachMapping(a => {
              q.addMapping({
                generated: {
                  line: r + a.generatedLine,
                  column: a.generatedColumn
                },
                original: { line: a.originalLine, column: a.originalColumn },
                source: c,
                name: a.name
              })
            })
        } catch (a) {
          m.error(
            `error while running sourcemap generation for plugin code that is babelled: \n\t [file]: ${c} \n\t [error info]: ${a}`
          )
        }
      else if (b.code) {
        q.setSourceContent(c, b.code)
        for (let a = 1, d = b.code.split('\n').length; a <= d; a++)
          q.addMapping({
            generated: { line: r + a, column: 0 },
            original: { line: a, column: 0 },
            source: c
          })
      }
      ;(r += b.code.split('\n').length), j.push(`})`), r++
    }
    let w = await g.getFileList(a)
    ;(v = {}),
      (o = []),
      w.forEach(a => {
        v[a] ||
          ((v[a] = !0),
          o.push(
            `global.__wxAppCurrentFile__ = "plugin-private://${c}/${a}.js"`
          ),
          o.push(`require("${a}.js")`))
      }),
      j.push(o.join(';')),
      r++
    const x = await f(a)
    if (x.publicComponents) {
      for (var y in ((o = []), x.publicComponents))
        o.push(
          `"plugin://${c}/${y}": "plugin-private://${c}/${
            x.publicComponents[y]
          }"`
        )
      j.push(`global.publishDomainComponents({${o.join(',')}})`), r++
    }
    return (
      x.main &&
        (j.push(`module.exports = function(){return require("${x.main}")}`),
        r++),
      j.push(`})
requirePlugin("plugin://${c}")
//# sourceMappingURL=appservice.js.map`),
      (r += 2),
      { key: `${c}_${e}`, code: j.join('\n'), sourcemap: q.toString() }
    )
  }
  module.exports = {
    getServiceCode: async (a, b = {}) => {
      const { pluginId: d, version: e } = b,
        f = `${d}_${e}`
      if ('dev' == e)
        return d == a.appid
          ? (await c(a), (o && o.key == f) || (o = await r(a, b)), o.code)
          : ''
      let g = await j.getCode(d, e)
      return g['/appservice.js']
    },
    getServiceCodeMap: async (a, b = {}) => {
      const { pluginId: c, version: d } = b
      return 'dev' == d && c == a.appid && o ? o.sourcemap : ''
    }
  }
})(require('lazyload'), require)
