import { useAuth } from "./useAuth.js";

/**
 * Global (auth/me) permission checks for route guards and global-scope UI.
 * Effective permissions come from the backend actor model (PermissionResolver, global scope).
 * Use this for settings, dashboard, and any page that is not in a specific company/project context.
 *
 * @returns {{ hasPermission: (name: string) => boolean, permissions: import('vue').Ref<string[]> }}
 */
export function usePermissions() {
  const { permissions } = useAuth();

  function hasPermission(name) {
    if (typeof name !== "string") return false;
    return (permissions.value ?? []).includes(name);
  }

  return {
    permissions,
    hasPermission,
  };
}
