/**
 * Board calendar date-label substitution per TZ §4.1.9 Tables 11 + 12.
 * Today → "Сегодня", tomorrow → "Завтра", otherwise dd.MM.yyyy.
 */

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type TFunction = (key: string, opts?: any) => string;

export function formatDateWithTodayTomorrow(
  date: Date | null | undefined,
  t: TFunction,
): string {
  if (!date) return "";
  const today = new Date();
  today.setHours(0, 0, 0, 0);
  const d = new Date(date);
  d.setHours(0, 0, 0, 0);
  const deltaDays = Math.round((d.getTime() - today.getTime()) / 86_400_000);
  if (deltaDays === 0) return t("SHARED.TODAY");
  if (deltaDays === 1) return t("SHARED.TOMORROW");
  const day = String(d.getDate()).padStart(2, "0");
  const month = String(d.getMonth() + 1).padStart(2, "0");
  return `${day}.${month}.${d.getFullYear()}`;
}
