import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";

import { CoinsRulesScreen } from "../coins-rules-screen";

vi.mock("@/stores/auth/auth-context", () => ({
  useAuthState: () => ({
    hasInitialized: true,
    isLoading: false,
    loginStatus: "email",
  }),
}));

vi.mock("@/stores/user/user-context", () => ({
  useUserDispatch: () => vi.fn(),
  useUserState: () => ({
    currentUser: null,
    entitlements: {
      quotas: {
        normalChatFreeDaily: 47,
        privateUnlockFreeDaily: 5,
      },
      costs: {
        normal_message: 3,
        private_message: 9,
        voice_message: 11,
        photo: 13,
        private_album_10: 101,
        private_album_20: 181,
      },
    },
  }),
}));

describe("CoinsRulesScreen", () => {
  it("renders outside CharacterProvider and returns to global profile", () => {
    const html = renderToStaticMarkup(
      <CoinsRulesScreen returnTo="/characters/maya/chat" />,
    );

    expect(html).toContain("Coin Usage Rules");
    expect(html).toContain(
      'href="/profile?returnTo=%2Fcharacters%2Fmaya%2Fchat"',
    );
    expect(html).toContain("47 free messages daily");
    expect(html).toContain("5 free private messages daily");
    expect(html).toContain("3 coins / message");
    expect(html).toContain("10 photos / 101 coins");
    expect(html).not.toContain("30 free messages daily");
    expect(html).not.toContain("2 free private messages daily");
  });
});
