import React from "react";
import { vi } from "vitest";
import { render } from "@testing-library/react";
import { Card } from "./index";
const setActiveScoreMock = vi.fn();
const useRootElementMock = vi.fn();
vi.mock("../context", () => ({
    useRootElement: () => useRootElementMock(),
}));
vi.mock("./Container", () => ({
    Container: ({ children, scoreKey, onClick, }) => (React.createElement("div", { "data-testid": "container", onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(scoreKey) }, children)),
}));
vi.mock("./ToggleIcon", () => ({
    ToggleIcon: ({ isExpandable }) => (React.createElement("div", { "data-testid": "toggle-icon" }, isExpandable ? "Expandable" : "Not Expandable")),
}));
vi.mock("./Title", () => ({
    Title: ({ children }) => (React.createElement("div", { "data-testid": "score-card-title" }, children)),
}));
vi.mock("./Value", () => ({
    Value: ({ scoreValue }) => (React.createElement("div", { "data-testid": "score-card-value" }, scoreValue)),
}));
vi.mock("./Description", () => ({
    Description: ({ children, isVisible, }) => isVisible ? (React.createElement("div", { "data-testid": "score-card-description" }, children)) : null,
}));
describe("Card", () => {
    beforeEach(() => {
        vi.resetAllMocks();
        useRootElementMock.mockReturnValue({
            activeScore: "",
            setActiveScore: setActiveScoreMock,
        });
    });
    it("renders title and value", () => {
        const { getByTestId } = render(React.createElement(Card, { title: "Test Score", scoreKey: "pedestrian_friendly", value: 4.5 }));
        expect(getByTestId("score-card-title").textContent).toBe("Test Score");
        expect(getByTestId("score-card-value").textContent).toBe("4.5");
    });
    it("renders description when active", () => {
        useRootElementMock.mockReturnValue({
            activeScore: "pedestrian_friendly",
            setActiveScore: setActiveScoreMock,
        });
        const { getByTestId } = render(React.createElement(Card, { title: "Test Score", scoreKey: "pedestrian_friendly", value: 4.5, description: "This is a test description." }));
        expect(getByTestId("score-card-description").textContent).toBe("This is a test description.");
    });
    it("does not render description when not active", () => {
        const { queryByTestId } = render(React.createElement(Card, { title: "Test Score", scoreKey: "pedestrian_friendly", value: 4.5, description: "This is a test description." }));
        expect(queryByTestId("score-card-description")).toBeNull();
    });
    it("calls onClick with correct parameters when activating a score", () => {
        const onClickMock = vi.fn();
        const { getByTestId } = render(React.createElement(Card, { title: "Test Score", scoreKey: "pedestrian_friendly", value: 4.5, description: "This is a test description.", onClick: onClickMock }));
        getByTestId("container").click();
        expect(onClickMock).toHaveBeenCalledWith("pedestrian_friendly", true);
    });
    it("calls onClick with correct parameters when deactivating a score", () => {
        const onClickMock = vi.fn();
        useRootElementMock.mockReturnValue({
            activeScore: "pedestrian_friendly",
            setActiveScore: setActiveScoreMock,
        });
        const { getByTestId } = render(React.createElement(Card, { title: "Test Score", scoreKey: "pedestrian_friendly", value: 4.5, description: "This is a test description.", onClick: onClickMock }));
        getByTestId("container").click();
        expect(onClickMock).toHaveBeenCalledWith("pedestrian_friendly", false);
    });
    it("calls setActiveScore with correct parameters when activating a score", () => {
        const { getByTestId } = render(React.createElement(Card, { title: "Test Score", scoreKey: "pedestrian_friendly", value: 4.5, description: "This is a test description." }));
        getByTestId("container").click();
        expect(setActiveScoreMock).toHaveBeenCalledWith("pedestrian_friendly");
    });
    it("calls setActiveScore with correct parameters when deactivating a score", () => {
        useRootElementMock.mockReturnValue({
            activeScore: "pedestrian_friendly",
            setActiveScore: setActiveScoreMock,
        });
        const { getByTestId } = render(React.createElement(Card, { title: "Test Score", scoreKey: "pedestrian_friendly", value: 4.5, description: "This is a test description." }));
        getByTestId("container").click();
        expect(setActiveScoreMock).toHaveBeenCalledWith("");
    });
});
//# sourceMappingURL=index.test.js.map