/* eslint-disable no-undef */
import { userStore } from '@/stores'
import { storeToRefs } from 'pinia'

const userPermissions: any = null
nextTick(() => {
  const { userInfo } = storeToRefs(userStore())
  // console.log(userInfo);
  // userPermissions = userinfo.permissions;
})

export default function (el: HTMLElement, { value }: { value: string | string[] | undefined }) {
  if (value === undefined) {
    return
  }
  if (typeof value === 'object') {
    if (value.every(val => !userPermissions.value.includes(val))) el.parentNode?.removeChild(el)
    return
  }
  if (!userPermissions.value.includes(value)) {
    if (el.className.includes('switch-box')) {
      el.classList.value += ' disabled'
      const elSwitch: HTMLElement = el.querySelector('.switch') as HTMLElement
      elSwitch.onclick = e => e.stopPropagation()

      const spans: NodeListOf<HTMLSpanElement> = el.querySelectorAll('span')
      spans.forEach(i => {
        i.onclick = e => e.stopPropagation()
      })
      return
    }
    el.parentNode?.removeChild(el)
  }
}
