import type { Directive } from 'vue'
import router from '@/router'
// 将评论内容中at 添加点击事件
export const vParseComment: Directive = {
  mounted(el: HTMLElement, binding: DirectiveBinding) {
    const { value: onClickedCallback } = binding

    el.querySelectorAll('span[data-id]').forEach((item) => {
      item.addEventListener('click', () => {
        const id = (item as HTMLElement).dataset.id
        const isReal = (item as HTMLElement).dataset.isreal
        if (id && isReal) {
          router.push(`/otherUserPage/${id}/${isReal}`)
          onClickedCallback?.()
        }
      })
    })
  },
}
