import type { TguPlanUi, TimelineRange } from "../../model/timelineTypes";

export const MAX_TGU_2D_MAP_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000;

export const TGU_2D_MAP_INTERVAL_WARNING =
  "Интервал карты больше 7 суток. Для тяжёлых canvas-слоёв выберите меньший интервал или конкретный план.";

export type Tgu2DMapIntervalState = {
  range: TimelineRange;
  tooLarge: boolean;
};

export function getTgu2DMapIntervalState(range: TimelineRange, selectedPlan?: TguPlanUi): Tgu2DMapIntervalState {
  if (selectedPlan) {
    return {
      range: {
        fromMs: selectedPlan.startMs,
        toMs: selectedPlan.endMs
      },
      tooLarge: false
    };
  }

  return {
    range,
    tooLarge: range.toMs - range.fromMs > MAX_TGU_2D_MAP_INTERVAL_MS
  };
}

