export function accountDisplayName(account, accounts = []) {
  if (!account) return "No account";
  const identity = account.displayName ?? account.email;
  return identity ?? account.label ?? "No account";
}

export function accountDisplayParts(account, accounts = []) {
  return accountIdentityParts(accountDisplayName(account, accounts));
}

export function accountIdentityParts(identity = "") {
  const at = identity.indexOf("@");
  return at > 0 ? { local: identity.slice(0, at), domain: identity.slice(at) } : { local: identity, domain: "" };
}

export function visibleAccountOptions(accounts) {
  return accounts;
}

export function accountStatusLabel(account) {
  if (!account || account.status !== "logged_in") return "Needs login";
  const plans = {
    free: "Free",
    go: "Go",
    plus: "Plus",
    pro: "Pro",
    prolite: "Pro Lite",
    team: "Team",
    self_serve_business_usage_based: "Business",
    business: "Business",
    enterprise_cbp_usage_based: "Enterprise",
    enterprise: "Enterprise",
    edu: "Edu"
  };
  return plans[account.planType] ?? "Logged in";
}
