'use strict'
var _extends =
  Object.assign ||
  function(a) {
    for (var b, c = 1; c < arguments.length; c++)
      for (var d in ((b = arguments[c]), b))
        Object.prototype.hasOwnProperty.call(b, d) && (a[d] = b[d])
    return a
  }
!(function(require, directRequire) {
  const a = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    b = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    c = require('./eadce02c750c875a10680bcfedadec88.js'),
    d = require('./5dc59f418d85e854c1a12d402d29e2d7.js'),
    {
      initMusic: e,
      playMusic: f,
      resumeMusic: g,
      stopMusic: h,
      pauseMusic: i,
      seekMusic: j,
      getAudioBufferd: k,
      getAudio: l
    } = require('./35a5c665bbd039baf968211c3ff216fc.js')
  module.exports = {
    getMusicPlayerState: async function(a, b) {
      var c = Math.floor
      const d = l()
      if (!d) return { errMsg: `${b.api}:ok`, status: 2 }
      try {
        return {
          dataUrl: d.src,
          duration: c(d.duration),
          currentPosition: c(d.currentTime),
          status: d.paused ? 0 : 1,
          downloadPercent: Math.round((100 * d.buffered.end(0)) / d.duration),
          errMsg: `${b.api}:ok`
        }
      } catch (a) {
        return { status: 2, errMsg: `${b.api}:ok` }
      }
    },
    operateMusicPlayer: async function(a, k) {
      let l = k.args,
        m = l.operationType
      if ('play' == m)
        e(a),
          f({ src: l.dataUrl || '', startTime: l.position || 0 }),
          a({
            type: b.SIMULATOR_SET_BACKGROUND_AUDIO,
            data: {
              mode: 'music',
              title: l.title || '',
              coverImgUrl: l.coverImgUrl || '',
              src: l.dataUrl || '',
              startTime: l.position || 0
            }
          }),
          a({ type: b.TOOLBAR_SET_CLICKKEY, data: c.MUSICCARD })
      else if ('resume' == m) g()
      else if ('pause' == m) {
        if (!i())
          return { errMsg: `${k.api}:fail background audio not playing` }
      } else if ('seek' == m) j({ currentTime: l.position })
      else if ('stop' == m) {
        if (!h())
          return { errMsg: `${k.api}:fail background audio not playing` }
        a({
          type: b.SIMULATOR_SET_BACKGROUND_AUDIO,
          data: { status: d.MUSIC_STATE_END }
        })
      } else return { errMsg: `${k.api}:fail illegal operationType` }
      return { errMsg: `${k.api}:ok` }
    },
    setBackgroundAudioState: async function(a, d) {
      e(a)
      let g = d.args
      return (
        f({ src: g.src, startTime: g.startTime || 0 }),
        a({
          type: b.SIMULATOR_SET_BACKGROUND_AUDIO,
          data: _extends({ mode: 'backgroundaudio' }, g)
        }),
        a({ type: b.TOOLBAR_SET_CLICKKEY, data: c.MUSICCARD }),
        { errMsg: `${d.api}:ok` }
      )
    },
    operateBackgroundAudio: async function(a, e) {
      let g = e.args,
        k = g.operationType
      if ('play' === k)
        f({ src: g.src, startTime: g.startTime || 0 }),
          a({
            type: b.SIMULATOR_SET_BACKGROUND_AUDIO,
            data: _extends({ mode: 'backgroundaudio' }, g)
          }),
          a({ type: b.TOOLBAR_SET_CLICKKEY, data: c.MUSICCARD })
      else if ('pause' === k) i()
      else if ('stop' === k)
        h(),
          a({
            type: b.SIMULATOR_SET_BACKGROUND_AUDIO,
            data: { status: d.MUSIC_STATE_END }
          })
      else if ('seek' === k) j({ currentTime: g.currentTime })
      else return { errMsg: `${e.api}:fail illegal operationType` }
      return { errMsg: `${e.api}:ok` }
    },
    getBackgroundAudioState: async function(b, c) {
      const d = a.getState(),
        e = d.music || {},
        f = l()
      return {
        duration: f ? f.duration : 0,
        currentTime: f ? f.currentTime : 0,
        paused: !f || f.paused,
        src: f ? f.src : '',
        buffered: k(),
        title: e.title || '',
        epname: e.epname || '',
        singer: e.singer || '',
        coverImgUrl: e.coverImgUrl || '',
        webUrl: e.webUrl || '',
        startTime: e.startTime || '',
        errMsg: `${c.api}:ok`
      }
    }
  }
})(require('lazyload'), require)
