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

import {
  getInsufficientCreditsMessageLimitView,
  shouldShowMessageLimitBanner,
} from "../chat-screen.helpers";

describe("getInsufficientCreditsMessageLimitView", () => {
  it("asks guests to log in for more free chats", () => {
    expect(getInsufficientCreditsMessageLimitView("guest")).toEqual({
      title: "Log in to get more free chats",
      description: "Free chats refresh every day.",
      ctaLabel: "Log in to continue",
      action: "auth",
    });
  });

  it("treats the transient not logged in state like guest", () => {
    expect(getInsufficientCreditsMessageLimitView("notLoggedIn")).toEqual({
      title: "Log in to get more free chats",
      description: "Free chats refresh every day.",
      ctaLabel: "Log in to continue",
      action: "auth",
    });
  });

  it.each(["email", "facebook", "google", "apple"] as const)(
    "asks %s users to top up credits",
    (loginStatus) => {
      expect(getInsufficientCreditsMessageLimitView(loginStatus)).toEqual({
        title: "Insufficient credits",
        description: "Free chats refresh every day.",
        ctaLabel: "Top up credits to continue",
        action: "topup",
      });
    },
  );
});

describe("shouldShowMessageLimitBanner", () => {
  it("shows only for visible insufficient credit prompts", () => {
    expect(
      shouldShowMessageLimitBanner({
        upgradePromptVisible: true,
        upgradeReason: "insufficient_credits",
      }),
    ).toBe(true);
  });

  it("hides when the prompt is not visible", () => {
    expect(
      shouldShowMessageLimitBanner({
        upgradePromptVisible: false,
        upgradeReason: "insufficient_credits",
      }),
    ).toBe(false);
  });

  it("hides when there is no upgrade reason", () => {
    expect(
      shouldShowMessageLimitBanner({
        upgradePromptVisible: true,
        upgradeReason: null,
      }),
    ).toBe(false);
  });
});
