import { parseISO, startOfISOWeek, endOfISOWeek, format, isValid } from "date-fns";

/**
 * Given a scheduled local-time ISO string, return the ISO-week bounds
 * (Monday/Sunday) as `dd.MM.yyyy` formatted strings.
 * Returns `{ start: "", end: "" }` for invalid or missing input.
 */
export function getWeekDateRange(scheduledLocal: string | undefined): {
  start: string;
  end: string;
} {
  if (!scheduledLocal) return { start: "", end: "" };
  const d = parseISO(scheduledLocal);
  if (!isValid(d)) return { start: "", end: "" };
  return {
    start: format(startOfISOWeek(d), "dd.MM.yyyy"),
    end: format(endOfISOWeek(d), "dd.MM.yyyy"),
  };
}
