import { notificationRowTone } from "../notifications/notification-types.js";

const ACTIVE_STATUSES = new Set(["starting", "running", "waiting_approval", "waiting_response"]);

export function chatRowStatus(thread, sessions = [], notifications = [], currentSession) {
  const matchesThread = (item) => item?.accountId === thread.ownerId && item.codexThreadId === thread.id;
  const session = matchesThread(currentSession)
    ? currentSession
    : sessions.find(matchesThread);
  if (!session) return "idle";

  const hasUnreadSessionNotification = notifications.some((item) => notificationRowTone(item.type) === "notification" && item.sessionId === session.id);
  if (hasUnreadSessionNotification) return "notification";
  if (ACTIVE_STATUSES.has(session.status)) return "active";
  return "idle";
}
