import { computed, type ComputedRef } from 'vue'
import type { MenuList } from '@/core/utils/filterMenuByPermission'
import { filterMenuByPermission } from '@/core/utils/filterMenuByPermission'
import { usePermissions } from './usePermissions'

export function useFilteredMenu(menu: MenuList): ComputedRef<MenuList> {
  const { activeRolePermissions, hasPermission } = usePermissions()

  return computed(() => {
    void activeRolePermissions.value

    return filterMenuByPermission(menu, hasPermission)
  })
}
