import { describe, it, expect } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { RunEtaPill } from "./run-eta-pill";

describe("RunEtaPill", () => {
  it("renders nothing for zero targets", () => {
    const html = renderToStaticMarkup(
      <RunEtaPill
        targetCount={0}
        fireAt={new Date("2026-05-13T09:00:00.000+08:00")}
        windowEndAt={new Date("2026-05-13T18:00:00.000+08:00")}
        timezone="Asia/Kuala_Lumpur"
      />,
    );
    expect(html).toBe("");
  });

  it("shows green 'Fits before deadline' when ETA finishes within the window", () => {
    const html = renderToStaticMarkup(
      <RunEtaPill
        targetCount={500}
        fireAt={new Date("2026-05-13T09:00:00.000+08:00")}
        windowEndAt={new Date("2026-05-13T18:00:00.000+08:00")}
        timezone="Asia/Kuala_Lumpur"
      />,
    );
    expect(html).toMatch(/Fits before deadline/);
    expect(html).toMatch(/min/);
    expect(html).not.toMatch(/Likely to pause/);
    expect(html).toContain("emerald");
  });

  it("shows amber 'Likely to pause' when ETA exceeds the window", () => {
    const html = renderToStaticMarkup(
      <RunEtaPill
        targetCount={5000}
        fireAt={new Date("2026-05-13T17:00:00.000+08:00")}
        windowEndAt={new Date("2026-05-13T18:00:00.000+08:00")}
        timezone="Asia/Kuala_Lumpur"
      />,
    );
    expect(html).toMatch(/Likely to pause/);
    expect(html).toMatch(/Push the deadline later/);
    expect(html).toContain("amber");
  });
});
