import { nextTick } from 'vue'
// import { useCssVar } from '@vueuse/core'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// const primaryColor = useCssVar('--el-color-primary', document.documentElement)

export const useNProgress = () => {
  NProgress.configure({ showSpinner: false })

  const initColor = async () => {
    await nextTick()
    const bar = document.getElementById('nprogress')?.getElementsByClassName('bar')[0]
    if (bar) {
      bar.style.background = 'primary'
    }
  }

  initColor()

  const start = () => {
    NProgress.start()
  }

  const done = () => {
    NProgress.done()
  }

  return {
    start,
    done
  }
}
