import { accountDisplayName } from "../accounts/account-display.js";

export function usageAccountLabel(account, accounts = []) {
  const displayName = accountDisplayName(account).trim();
  const identity = accountIdentityKey(account);
  if (!identity) return displayName;
  const repeated = accounts.filter((item) => accountIdentityKey(item) === identity).length > 1;
  return repeated ? `${displayName} · ${account.id}` : displayName;
}

function accountIdentityKey(account) {
  const identity = account?.displayName ?? account?.email;
  return typeof identity === "string" ? identity.trim().toLowerCase() : "";
}
