"use client"

import type { Email } from "@/lib/email-data"

export type ListMailIndex = {
  emailById: Map<string, Email>
  scheduledIds: Set<string>
}

export function buildListMailIndex(emails: Email[]): ListMailIndex {
  const emailById = new Map<string, Email>()
  const scheduledIds = new Set<string>()
  for (const e of emails) {
    emailById.set(e.id, e)
    if (e.labels?.includes("scheduled")) scheduledIds.add(e.id)
  }
  return { emailById, scheduledIds }
}

export type MailRowFlags = {
  isRead: boolean
  isStarred: boolean
  isImportant: boolean
}

export function useMailRowFlags(email: Email): MailRowFlags {
  return {
    isRead: email.read,
    isStarred: email.starred,
    isImportant: email.important,
  }
}
