/**
 * 邮箱展示脱敏：@ 前本地名保留首尾各 2 位，中间用 *；域名完整展示。
 * 例：jason3@g.com → ja**n3@g.com
 */
export function maskEmailForDisplay(email: string): string {
  const s = email.trim()
  if (!s) {
    return '—'
  }
  const at = s.indexOf('@')
  if (at <= 0) {
    return s
  }
  const local = s.slice(0, at)
  const domain = s.slice(at)
  const n = local.length
  if (n <= 0) {
    return s
  }
  if (n <= 2) {
    return '*'.repeat(n) + domain
  }
  if (n === 3) {
    return local[0] + '*' + local[2] + domain
  }
  if (n === 4) {
    return local + domain
  }
  const head = local.slice(0, 2)
  const tail = local.slice(-2)
  const stars = '*'.repeat(n - 4)
  return head + stars + tail + domain
}
