import DOMPurify from 'dompurify'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.directive('dompurify-html', {
    mounted(el: HTMLElement, binding: any) {
      if (binding.value) {
        el.innerHTML = DOMPurify.sanitize(binding.value)
      }
    },
    updated(el: HTMLElement, binding: any) {
      if (binding.value) {
        el.innerHTML = DOMPurify.sanitize(binding.value)
      }
    }
  })
})
