'use strict'
!(function(require, directRequire) {
  async function a() {
    const a = global.windowMap.get('MAIN').window
    let b = document.createElement('input')
    return (
      (b.style.display = 'none'),
      b.setAttribute('type', 'file'),
      b.setAttribute('accept', 'image/*'),
      a.document.body.appendChild(b),
      b.click(),
      h('chooseFile'),
      new Promise(c => {
        b.addEventListener('change', () => {
          a.document.body.removeChild(b),
            i('chooseFile'),
            c({ success: !0, filePath: b.value })
        }),
          b.addEventListener('cancel', () => {
            a.document.body.removeChild(b), i('chooseFile'), c({ success: !1 })
          })
      })
    )
  }
  const b = require('fs'),
    c = require('path'),
    d = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    e = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    f = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    g = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    {
      enterBackground: h,
      enterForeground: i
    } = require('./a3959bb900db9f65ed2e9c5dfa6977b7.js')
  module.exports = {
    scanCode: async function(c, h) {
      if (global.autoTest) return { errMsg: `${h.api}:cancel` }
      const i = f.getCurrent(),
        j = g.getState(),
        k = j.toolbar.network.current
      if ('none' === k) return { errMsg: `${h.api}:fail network is down` }
      let l = await a()
      if (l.success) {
        let a = l.filePath,
          { body: c } = await d({
            url: `${e.jsDecodeQRCodeURL}`,
            method: 'post',
            body: b.readFileSync(a),
            needToken: 1,
            needAppID: 1
          })
        if (c.result || c.path) {
          let a = c.path ? decodeURIComponent(c.path) : '',
            b = {
              errMsg: `${h.api}:ok`,
              result: c.result,
              scanType: c.scan_type,
              charSet: c.char_set
            }
          return a && (b.path = a), b
        }
        return { errMsg: `${h.api}:fail` }
      }
      return { errMsg: `${h.api}:cancel` }
    }
  }
})(require('lazyload'), require)
