import type { ActivityEntry } from "./types";

export type ActivityType = "all" | "task" | "board" | "calendar" | "note" | "focus" | "mail" | "invite" | "system";

const activityTypeLabels: Record<ActivityType, string> = {
  all: "All",
  task: "Tasks",
  board: "Board",
  calendar: "Calendar",
  note: "Notes",
  focus: "Focus",
  mail: "Mail",
  invite: "Invites",
  system: "System"
};

export function listActivityTypeOptions(): Array<{ value: ActivityType; label: string }> {
  return (Object.keys(activityTypeLabels) as ActivityType[]).map(value => ({
    value,
    label: activityTypeLabels[value]
  }));
}

export function classifyActivity(entry: ActivityEntry): Exclude<ActivityType, "all"> {
  const text = `${entry.title} ${entry.detail}`.toLowerCase().trim();

  if (text.includes("invite")) {
    return "invite";
  }
  if (text.includes("board")) {
    return "board";
  }
  if (text.includes("mail") || text.includes("inbox") || text.includes("smtp") || text.includes("imap")) {
    return "mail";
  }
  if (text.includes("calendar") || text.includes("event")) {
    return "calendar";
  }
  if (text.includes("note")) {
    return "note";
  }
  if (text.includes("focus") || text.includes("pomodoro")) {
    return "focus";
  }
  if (text.includes("task")) {
    return "task";
  }
  return "system";
}

export function getActivityTypeLabel(type: Exclude<ActivityType, "all">): string {
  return activityTypeLabels[type];
}
