import { requiredPagePermissionsMap } from "@archestra/shared/access-control";
import { usePermissionMap } from "@/lib/auth/auth.query";

import { useSecretsType } from "@/lib/secrets.query";

export function useSettingsTabs() {
  const permissionMap = usePermissionMap(requiredPagePermissionsMap);
  const { data: secretsType } = useSecretsType();
  return [
    { label: "Your Account", href: "/settings/account" },
    ...(permissionMap?.["/settings/api-keys"]
      ? [{ label: "API Keys", href: "/settings/api-keys" }]
      : []),
    ...(permissionMap?.["/settings/service-accounts"]
      ? [{ label: "Service Accounts", href: "/settings/service-accounts" }]
      : []),
    ...(permissionMap?.["/settings/agents"]
      ? [{ label: "Agents", href: "/settings/agents" }]
      : []),
    ...(permissionMap?.["/settings/llm"]
      ? [{ label: "LLM", href: "/settings/llm" }]
      : []),
    ...(permissionMap?.["/settings/knowledge"]
      ? [{ label: "Knowledge", href: "/settings/knowledge" }]
      : []),
    ...(permissionMap?.["/settings/environments"]
      ? [{ label: "Environments", href: "/settings/environments" }]
      : []),
    ...(permissionMap?.["/settings/users"]
      ? [{ label: "Users", href: "/settings/users" }]
      : []),
    ...(permissionMap?.["/settings/teams"]
      ? [{ label: "Teams", href: "/settings/teams" }]
      : []),
    ...(permissionMap?.["/settings/roles"]
      ? [{ label: "Roles", href: "/settings/roles" }]
      : []),
    ...(permissionMap?.["/settings/github"]
      ? [{ label: "GitHub", href: "/settings/github" }]
      : []),
    // Always render the Identity Providers tab when the user has the
    // permission — the destination page handles dimming when the enterprise
    // license is inactive, no need to gate the nav entry as well.
    ...(permissionMap?.["/settings/identity-providers"]
      ? [{ label: "Identity Providers", href: "/settings/identity-providers" }]
      : []),
    ...(secretsType?.type === "Vault" && permissionMap?.["/settings/secrets"]
      ? [{ label: "Secrets", href: "/settings/secrets" }]
      : []),
    ...(permissionMap?.["/settings/organization"]
      ? [{ label: "Organization", href: "/settings/organization" }]
      : []),
  ];
}
