import { jsx as _jsx } from "react/jsx-runtime";
import { describe, it, expect, vi, afterEach } from "vitest";
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
import { ThreadItemWrapper } from "../ThreadItemWrapper";
import { JumpToLatestButton } from "../JumpToLatestButton";
afterEach(() => {
    cleanup();
    vi.restoreAllMocks();
});
// ---------------------------------------------------------------------------
// ThreadItemWrapper
// ---------------------------------------------------------------------------
describe("ThreadItemWrapper", () => {
    it("applies stgm-thread-item-enter class on mount when animate=true", () => {
        const { container } = render(_jsx(ThreadItemWrapper, { animate: true, children: _jsx("span", { children: "content" }) }));
        const wrapper = container.firstElementChild;
        expect(wrapper.classList.contains("stgm-thread-item-enter")).toBe(true);
        expect(screen.getByText("content")).toBeTruthy();
    });
    it("removes animation class after animationend", () => {
        const { container } = render(_jsx(ThreadItemWrapper, { animate: true, children: _jsx("span", { children: "content" }) }));
        const wrapper = container.firstElementChild;
        expect(wrapper.classList.contains("stgm-thread-item-enter")).toBe(true);
        fireEvent.animationEnd(wrapper);
        expect(container.querySelector(".stgm-thread-item-enter")).toBeNull();
        expect(screen.getByText("content")).toBeTruthy();
    });
    it("renders children directly when animate=false (no wrapper div)", () => {
        const { container } = render(_jsx(ThreadItemWrapper, { animate: false, children: _jsx("span", { "data-testid": "child", children: "no-animation" }) }));
        expect(container.querySelector(".stgm-thread-item-enter")).toBeNull();
        expect(screen.getByTestId("child")).toBeTruthy();
    });
    it("renders children directly after animation completes (no residual wrapper)", () => {
        const { container, rerender } = render(_jsx(ThreadItemWrapper, { animate: true, children: _jsx("span", { children: "content" }) }));
        const wrapper = container.firstElementChild;
        fireEvent.animationEnd(wrapper);
        rerender(_jsx(ThreadItemWrapper, { animate: true, children: _jsx("span", { children: "content" }) }));
        const span = screen.getByText("content");
        expect(span.tagName).toBe("SPAN");
        expect(container.querySelector(".stgm-thread-item-enter")).toBeNull();
    });
});
// ---------------------------------------------------------------------------
// JumpToLatestButton
// ---------------------------------------------------------------------------
describe("JumpToLatestButton", () => {
    it("renders visible state with correct attributes", () => {
        const onClick = vi.fn();
        render(_jsx(JumpToLatestButton, { onClick: onClick, visible: true }));
        const button = screen.getByRole("button", { name: "Jump to latest" });
        expect(button.getAttribute("aria-hidden")).toBe("false");
        expect(button.getAttribute("tabindex")).toBe("0");
        expect(button.className).toContain("opacity-100");
        expect(button.className).toContain("pointer-events-auto");
    });
    it("renders hidden state with correct attributes", () => {
        const onClick = vi.fn();
        render(_jsx(JumpToLatestButton, { onClick: onClick, visible: false }));
        const button = screen.getByLabelText("Jump to latest");
        expect(button.getAttribute("aria-hidden")).toBe("true");
        expect(button.getAttribute("tabindex")).toBe("-1");
        expect(button.className).toContain("opacity-0");
        expect(button.className).toContain("pointer-events-none");
        expect(button.className).toContain("translate-y-2");
    });
    it("calls onClick when clicked in visible state", () => {
        const onClick = vi.fn();
        render(_jsx(JumpToLatestButton, { onClick: onClick, visible: true }));
        fireEvent.click(screen.getByRole("button", { name: "Jump to latest" }));
        expect(onClick).toHaveBeenCalledOnce();
    });
    it("has transition classes for smooth enter/exit", () => {
        const onClick = vi.fn();
        render(_jsx(JumpToLatestButton, { onClick: onClick, visible: true }));
        const button = screen.getByRole("button", { name: "Jump to latest" });
        expect(button.className).toContain("transition-[opacity,transform]");
    });
});
//# sourceMappingURL=thread-animation.test.js.map