import { describe, expect, it } from "vitest";

import { deriveChatSupportCta } from "../chat-support-cta";

describe("deriveChatSupportCta", () => {
  const now = Date.parse("2026-07-28T00:00:00.000Z");

  it("shows first recharge ahead of a weaker role offer without inventing a timer", () => {
    expect(
      deriveChatSupportCta({
        isFirstRecharge: true,
        commercialOffer: {
          enabled: true,
          commercialOfferId: "offer-1",
          characterId: "elio",
          planId: "vip_annual",
          discountPercent: 30,
          pricePercent: 70,
          expiresAt: "2026-07-29T00:00:00.000Z",
          triggerReason: "price_objection",
          message: "I got this for you.",
        },
        nowMs: now,
      }),
    ).toMatchObject({
      kind: "firstRecharge",
      label: "Support me · 50% OFF · First recharge",
      commercialOfferId: null,
      expiresAt: null,
    });
  });

  it("shows a server-anchored 24-hour role offer countdown", () => {
    expect(
      deriveChatSupportCta({
        isFirstRecharge: false,
        commercialOffer: {
          enabled: true,
          commercialOfferId: "offer-1",
          characterId: "maya-tan",
          planId: "vip_annual",
          discountPercent: 30,
          pricePercent: 70,
          expiresAt: "2026-07-29T00:00:00.000Z",
          triggerReason: "price_objection",
          message: "I got this for you.",
        },
        nowMs: now,
      }),
    ).toMatchObject({
      kind: "commercialOffer",
      label: "Support me · 30% OFF · 23:59:59",
      commercialOfferId: "offer-1",
      expiresAt: "2026-07-29T00:00:00.000Z",
    });
  });

  it("returns to Support me after an offer expires or is absent", () => {
    expect(
      deriveChatSupportCta({
        isFirstRecharge: false,
        commercialOffer: null,
        nowMs: now,
      }).label,
    ).toBe("Support me");
    expect(
      deriveChatSupportCta({
        isFirstRecharge: false,
        commercialOffer: {
          enabled: true,
          commercialOfferId: "offer-1",
          characterId: "elio",
          planId: "vip_annual",
          discountPercent: 30,
          pricePercent: 70,
          expiresAt: "2026-07-27T00:00:00.000Z",
          triggerReason: "price_objection",
          message: "I got this for you.",
        },
        nowMs: now,
      }).label,
    ).toBe("Support me");
  });
});
