import { useNuxtApp, useState } from "#imports";
function withPermissionFallback(state) {
  const permissions = Array.isArray(state?.permissions) ? state.permissions : [];
  return {
    ...state,
    hasPermission: state?.hasPermission ?? ((permissionId) => permissions.includes(permissionId))
  };
}
export function useAuthentication() {
  const nuxtApp = useNuxtApp();
  const injected = nuxtApp.$appAuthentication;
  if (typeof injected === "function") {
    return withPermissionFallback(injected());
  }
  if (injected) {
    return withPermissionFallback(injected);
  }
  const state = useState("authentication", () => ({}));
  return withPermissionFallback(state.value);
}
