<script setup lang="ts">
import { propTypes } from '@/utils/propTypes'
import { computed, unref } from 'vue'
import { useUserStore } from '@/store/modules/user'

const props = defineProps({
  permission: propTypes.string.def()
})

const currentPermission = computed(() => {
  return useUserStore().getRoleName || []
})

const hasPermission = computed(() => {
  const permission = unref(props.permission)
  if (!permission) {
    return true
  }
  return unref(currentPermission).includes(permission)
})
</script>

<template>
  <template v-if="hasPermission">
    <slot></slot>
  </template>
</template>
