import { describe, it, expect } from "vitest";
import { computeBalanceDateRange } from "./useBalanceOverview";

const FIXED_TODAY = new Date(2026, 3, 25); // local 2026-04-25

describe("computeBalanceDateRange", () => {
  it("returns an empty range for 'all'", () => {
    expect(computeBalanceDateRange("all", FIXED_TODAY)).toEqual({});
  });

  it("subtracts 90 days for 3M and emits a from-only range", () => {
    const r = computeBalanceDateRange("3M", FIXED_TODAY);
    expect(r.to).toBeUndefined();
    expect(r.from).toBe("2026-01-25");
  });

  it("subtracts 180 days for 6M", () => {
    const r = computeBalanceDateRange("6M", FIXED_TODAY);
    expect(r.from).toBe("2025-10-27");
  });

  it("subtracts 365 days for 1A", () => {
    const r = computeBalanceDateRange("1A", FIXED_TODAY);
    expect(r.from).toBe("2025-04-25");
  });

  it("subtracts 1095 days for 3A", () => {
    const r = computeBalanceDateRange("3A", FIXED_TODAY);
    expect(r.from).toBe("2023-04-26");
  });

  it("emits ISO-8601 zero-padded month/day", () => {
    // 2026-01-05 → 3M → 2025-10-07; both fields zero-padded.
    const today = new Date(2026, 0, 5);
    const r = computeBalanceDateRange("3M", today);
    expect(r.from).toMatch(/^\d{4}-\d{2}-\d{2}$/);
    expect(r.from).toBe("2025-10-07");
  });
});
