import type { Ref } from 'vue'
import { userStore } from '@/stores'
import { storeToRefs } from 'pinia'

let AUTH: Ref<string[]>
nextTick(() => {
  const { auth } = storeToRefs(userStore())
  AUTH = auth
})

// eslint-disable-next-line max-params
export default function (el: HTMLElement, { value }: { value: string }) {
  el.parentNode.style.display = 'block'
  function remove() {
    el.parentNode.style.display = 'none'
    // el.parentNode?.removeChild(el);
  }
  if (!value) {
    return remove()
  }
  if (value.startsWith('qyn://')) {
    const path = value.split('qyn://')[1]
    if (!path) return remove()
    if (!AUTH.value.some(i => i === path)) return remove()
  } else if (value.startsWith('qy://')) {
    const path = value.split('qy://')[1]
    if (!path) return remove()
  }
}
