import { nextTick, unref } from 'vue'
import { useConfig } from '@/store/modules/asideConfig'

const downloadSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 1024 1024"><path fill="currentColor" d="M505.7 661a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"></path></svg>'

export function hideDownload(e: MouseEvent) {
  nextTick(() => {
    const configStore = useConfig()
    const downloadEle: any = document.querySelector('.n-image-preview-toolbar')?.children[5]
    const asideValue = unref(configStore.getAsideValue)
    const download = asideValue?.izimgdownload
    if (downloadEle && downloadEle.innerHTML === downloadSvg && download === false)
      downloadEle.style.display = 'none'
    else
      downloadEle.style.display = 'block'
  })
}
