/** Predefined colors for collaborative cursors */
const CURSOR_COLORS = [
  '#f43f5e', // rose
  '#6366f1', // indigo
  '#10b981', // emerald
  '#f59e0b', // amber
  '#0ea5e9', // sky
  '#8b5cf6', // violet
  '#14b8a6', // teal
  '#ef4444', // red
]

/** Assign a stable color based on user ID */
export function getUserColor(userId: string): string {
  let hash = 0
  for (let i = 0; i < userId.length; i++) {
    hash = ((hash << 5) - hash + userId.charCodeAt(i)) | 0
  }
  return CURSOR_COLORS[Math.abs(hash) % CURSOR_COLORS.length]
}

/** Get display name from email */
export function getDisplayName(email: string | undefined): string {
  if (!email) return 'Anonymous'
  const atIndex = email.indexOf('@')
  return atIndex > 0 ? email.slice(0, atIndex) : email
}
