import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import SwipeableCard from "./SwipeableCard";
import { TEST_RESTAURANT } from "@/__tests__/helpers/fixtures";

vi.mock("./RestaurantCard", () => ({
  default: ({ restaurant }: { restaurant: { name: string } }) => (
    <div data-testid="restaurant-card">{restaurant.name}</div>
  ),
}));

describe("SwipeableCard", () => {
  it("renders restaurant card", () => {
    render(
      <SwipeableCard
        restaurant={TEST_RESTAURANT}
        isTop
        onSwipe={() => {}}
        likeCount={0}
      />,
    );
    expect(screen.getByTestId("restaurant-card")).toBeInTheDocument();
    expect(screen.getByText("测试餐厅")).toBeInTheDocument();
  });

  it("renders swipe overlays (LIKE and NOPE)", () => {
    const { container } = render(
      <SwipeableCard
        restaurant={TEST_RESTAURANT}
        isTop
        onSwipe={() => {}}
        likeCount={0}
      />,
    );
    expect(container.textContent).toContain("LIKE");
    expect(container.textContent).toContain("NOPE");
  });

  it("calls registerSwipe when provided and isTop", () => {
    const registerSwipe = vi.fn();
    render(
      <SwipeableCard
        restaurant={TEST_RESTAURANT}
        isTop
        onSwipe={() => {}}
        registerSwipe={registerSwipe}
        likeCount={0}
      />,
    );
    expect(registerSwipe).toHaveBeenCalledWith(expect.any(Function));
  });

  it("does not pass registerSwipe for non-top cards", () => {
    render(
      <SwipeableCard
        restaurant={TEST_RESTAURANT}
        isTop={false}
        onSwipe={() => {}}
        likeCount={0}
      />,
    );
    expect(screen.getByTestId("restaurant-card")).toBeInTheDocument();
  });

  it("displays like count", () => {
    render(
      <SwipeableCard
        restaurant={TEST_RESTAURANT}
        isTop
        onSwipe={() => {}}
        likeCount={3}
      />,
    );
    expect(screen.getByTestId("restaurant-card")).toBeInTheDocument();
  });
});
