import useMemberStore from '@/stores/member'
import { storeToRefs } from 'pinia'
import { computed } from 'vue'
export default function usePermission() {
    const { btnPermission } = storeToRefs(useMemberStore())
    const checkPermission = (code: string | string[]) => {
        if (!btnPermission.value?.length) return false
        
        return Array.isArray(code)
            ? code.some(c => btnPermission.value?.includes(c))
            : btnPermission.value.includes(code)
    }
    const hasPermission = computed(() => (code: string | string[]) => {
        return checkPermission(code)
    })
    return {
        checkPermission,
        hasPermission
    }
}