import { describe, expect, it } from "vitest";
import type { TguPlanUi } from "../../model/timelineTypes";
import { DEFAULT_TGU_2D_MAP_LAYERS } from "./model/mapLayerTypes";
import { getTgu2DMapIntervalState } from "./tgu2DMapInterval";
import { parseLocal } from "../../utils/localTime";

function plan(startTime: string, endTime: string): TguPlanUi {
  return {
    planId: "plan-1",
    spacecraftId: "56756",
    startTime,
    endTime,
    kppId: "KPP-1",
    status: "PLANNED",
    startMs: parseLocal(startTime),
    endMs: parseLocal(endTime)
  };
}

describe("tgu2DMapInterval", () => {
  it("marks common map interval longer than 7 days as too large", () => {
    const state = getTgu2DMapIntervalState({
      fromMs: parseLocal("2026-05-29T00:00:00"),
      toMs: parseLocal("2026-06-05T00:00:01")
    });

    expect(state.tooLarge).toBe(true);
  });

  it("uses selected plan interval without the common interval restriction", () => {
    const selectedPlan = plan("2026-05-29T01:00:00", "2026-06-07T02:00:00");
    const state = getTgu2DMapIntervalState(
      {
        fromMs: parseLocal("2026-05-29T00:00:00"),
        toMs: parseLocal("2026-06-10T00:00:00")
      },
      selectedPlan
    );

    expect(state).toEqual({
      range: {
        fromMs: selectedPlan.startMs,
        toMs: selectedPlan.endMs
      },
      tooLarge: false
    });
  });

  it("enables plan, stations and requests layers by default", () => {
    expect(DEFAULT_TGU_2D_MAP_LAYERS).toEqual({
      tracks: false,
      swath: false,
      planWorks: true,
      complexPlan: false,
      heatmap: false,
      stations: true,
      spacecraftMarkers: false,
      requests: true
    });
  });
});

