import { getActiveScheduleSlots } from "./slot-check";
import { buildPlannedScheduleView } from "./resolve-schedule";

export function describeScheduleStatus(input: {
  projectId: string;
  timezone: string;
  postsPerDay: 1 | 2;
  scheduleSeed?: number;
  now?: Date;
}): string {
  const view = buildPlannedScheduleView({
    projectId: input.projectId,
    timezone: input.timezone,
    postsPerDay: input.postsPerDay,
    scheduleSeed: input.scheduleSeed,
  });

  const active = getActiveScheduleSlots({
    timezone: input.timezone,
    postsPerDay: input.postsPerDay,
    scheduleSeed: view.scheduleSeed,
    now: input.now,
  });

  if (active.length) {
    return `Now · ${active[0].label} slot (${view.timezoneLabel})`;
  }

  return view.summary;
}

export function formatQueuedPublishMessage(input: {
  projectId: string;
  timezone: string;
  postsPerDay: 1 | 2;
  scheduleSeed?: number;
  queuedCount: number;
}): string {
  const view = buildPlannedScheduleView({
    projectId: input.projectId,
    timezone: input.timezone,
    postsPerDay: input.postsPerDay,
    scheduleSeed: input.scheduleSeed,
  });

  const times = view.slots.map((s) => s.display).join(" · ");

  return `${input.queuedCount} post(s) waiting — cron publishes to LinkedIn at the next slot (${times} ${view.timezoneLabel}). You do not need to click Generate Now again.`;
}
