import { screen, cleanup } from "@testing-library/react";
import { expect, test, vi, beforeEach, afterEach } from "vitest";
import SignupPage from "./page";
import { renderWithProviders } from "../test-utils";

const mockPush = vi.fn();
vi.mock("next/navigation", () => ({
  useRouter: () => ({ push: mockPush }),
  useSearchParams: () => ({ get: () => null }),
}));

const mockRegister = vi.fn();
vi.mock("../auth-context", () => ({
  useAuth: () => ({ user: null, register: mockRegister }),
  AuthProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));

beforeEach(() => vi.clearAllMocks());
afterEach(() => cleanup());

test("renders signup form with title", () => {
  renderWithProviders(<SignupPage />);
  // Step 1 shows "Join with Invite" title (invite code entry)
  expect(screen.getByRole("heading", { name: "Únete con Invitación" })).toBeDefined();
});

test("renders invite code input", () => {
  renderWithProviders(<SignupPage />);
  expect(screen.getByLabelText("Código de Invitación")).toBeDefined();
});

test("renders continue button", () => {
  renderWithProviders(<SignupPage />);
  expect(screen.getByRole("button", { name: "Continuar" })).toBeDefined();
});

test("renders link to login", () => {
  renderWithProviders(<SignupPage />);
  expect(screen.getByText("Iniciar sesión")).toBeDefined();
});
