'use strict'
!(function(require, directRequire) {
  let a
  module.exports = {
    open: async function() {
      return new Promise((b, c) => {
        a && a.close()
        let d = indexedDB.open('devtools', 1)
        ;(d.onerror = function(a) {
          c(a)
        }),
          (d.onsuccess = function(c) {
            ;(a = c.target.result), b(a)
          }),
          (d.onupgradeneeded = function(c) {
            a = c.target.result
            let d = a.createObjectStore('noticecenter', {
              keyPath: 'id',
              autoIncrement: !0
            })
            d.createIndex('title', 'title', { unique: !1 }),
              d.createIndex('content', 'content', { unique: !1 }),
              d.createIndex('link', 'link', { unique: !1 }),
              d.createIndex('timestamp', 'timestamp', { unique: !1 }),
              b(a)
          })
      })
    },
    close: async function() {
      a && (a.close(), (a = void 0))
    },
    insert: async function(b, c) {
      return new Promise((d, f) => {
        let g = a.transaction([b], 'readwrite').objectStore(b),
          h = 0
        c.forEach(a => {
          let b = g.add(a)
          ;(b.onerror = a => {
            f(a)
          }),
            (b.onsuccess = () => {
              h++, h == c.length && d()
            })
        })
      })
    },
    remove: async function(b, c) {
      return new Promise((d, f) => {
        let g = a.transaction([b], 'readwrite').objectStore(b),
          h = 0
        c.forEach(a => {
          let b = g.delete(a)
          ;(b.onerror = a => {
            f(a)
          }),
            (b.onsuccess = () => {
              h++, h == c.length && d()
            })
        })
      })
    },
    getByKey: async function(b, c) {
      return new Promise((d, f) => {
        let g = a.transaction([b], 'readonly').objectStore(b),
          h = g.get(c)
        ;(h.onerror = function(a) {
          f(a)
        }),
          (h.onsuccess = function(a) {
            d(a.target.result)
          })
      })
    },
    getByPage: async function(b, c = 0, d = 20) {
      return new Promise((f, g) => {
        let h = a.transaction([b], 'readonly').objectStore(b),
          i = IDBKeyRange.lowerBound(c, !0),
          j = h.openCursor(i, 'nextunique'),
          k = []
        ;(j.onsuccess = a => {
          let b = a.target.result
          b
            ? (k.push(b.value),
              k.length >= d ? f({ end: !1, result: k }) : b.continue())
            : f({ end: !0, result: k })
        }),
          (j.onerror = a => {
            g(a)
          })
      })
    },
    update: async function(b, c, d) {
      return new Promise((f, g) => {
        let h = a.transaction([b], 'readwrite').objectStore(b),
          i = h.get(c)
        ;(i.onerror = a => {
          g(a)
        }),
          (i.onsuccess = () => {
            var a = e.target.result
            for (c in d) a[c] = d[c]
            h.put(a), f(a)
          })
      })
    },
    getByPageReverse: async function(b, c = Number.MAX_SAFE_INTEGER, d = 20) {
      return new Promise((f, g) => {
        let h = a.transaction([b], 'readonly').objectStore(b),
          i = IDBKeyRange.upperBound(c, !0),
          j = h.openCursor(i, 'prevunique'),
          k = []
        ;(j.onsuccess = a => {
          let b = a.target.result
          b
            ? (k.push(b.value),
              k.length >= d ? f({ end: !1, result: k }) : b.continue())
            : f({ end: !0, result: k })
        }),
          (j.onerror = a => {
            g(a)
          })
      })
    },
    removeAll: async function(b) {
      return new Promise((c, d) => {
        let f = a.transaction([b], 'readwrite').objectStore(b),
          g = IDBKeyRange.lowerBound(0),
          h = f.delete(g)
        ;(h.onerror = a => {
          d(a)
        }),
          (h.onsuccess = () => {
            c()
          })
      })
    }
  }
})(require('lazyload'), require)
