import { describe, expect, it } from "vitest";
import { buildPriority1CalendarGrid } from "@/lib/priority1/calendar-grid";

describe("buildPriority1CalendarGrid", () => {
  it("接受 MM/DD/YYYY 提货日并生成当月日历", () => {
    const { monthLabel, cells } = buildPriority1CalendarGrid("07/15/2026", []);
    expect(monthLabel).toBe("Jul");
    expect(cells.length).toBeGreaterThan(28);
  });

  it("优先按 FTL 日历行里的实际日期落格", () => {
    const { cells } = buildPriority1CalendarGrid("07/15/2026", [
      {
        rank: 1,
        carrier: "FTL 日历报价",
        carrierCode: "",
        totalUsd: 1652.16,
        markup_amount: 0,
        final_total_usd: 1652.16,
        transitDays: 0,
        deliveryDate: "DAY:1",
        expirationDate: null,
        serviceLevel: "FTL Calendar",
        quoteId: null,
        caboUrl: null,
        source: "ftl-calendar",
      },
      {
        rank: 2,
        carrier: "FTL 日历报价",
        carrierCode: "",
        totalUsd: 2178.47,
        markup_amount: 0,
        final_total_usd: 2178.47,
        transitDays: 0,
        deliveryDate: "DAY:6",
        expirationDate: null,
        serviceLevel: "FTL Calendar",
        quoteId: null,
        caboUrl: null,
        source: "ftl-calendar",
      },
    ]);

    const day1 = cells.find((cell) => cell.inMonth && cell.date.getDate() === 1);
    const day6 = cells.find((cell) => cell.inMonth && cell.date.getDate() === 6);
    expect(day1?.priceUsd).toBe(1652.16);
    expect(day6?.priceUsd).toBe(2178.47);
  });
});
