import InfoButton from "$/component/button/InfoButton";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";


const buttonText = "Info Button";


describe("InfoButton Component", () => {
	it("Renders with defaults", () => {
		render(<InfoButton>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		//Check button requirements
		expect(button).toBeInTheDocument();
		expect(button).toHaveTextContent(buttonText);
		//Classes
		expect(button).toHaveClass("rounded-lg");
		expect(button).toHaveClass("px-4", "py-2");
		expect(button).toHaveClass("border");
		expect(button).toHaveClass("cursor-pointer");
		//Colors
		expect(button).toHaveClass("bg-info", "active:bg-info-dark");
		expect(button).toHaveClass("border-info", "active:border-info-dark");
		expect(button).toHaveClass("text-black");
	});

	it("Renders with custom className", () => {
		const customClass = "custom-info-button-class";

		render(<InfoButton className={customClass}>{buttonText}</InfoButton>);

		//Check button requirements
		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass(customClass);
	});

	it("Renders with aria-label", () => {
		const ariaLabel = "Info Button Aria Label";

		render(<InfoButton aria-label={ariaLabel}>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveAttribute("aria-label", ariaLabel);
	});

	it("Renders with onClick handler", async () => {
		const handleClick = vi.fn();

		render(<InfoButton onClick={handleClick}>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();

		await userEvent.click(button);
		expect(handleClick).toHaveBeenCalledTimes(1);
	});

	describe("InfoButton Component Rounding", () => {
		it("Renders with small rounding", () => {
			render(<InfoButton rounding="sm">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("rounded-sm");
		});
		it("Renders with medium rounding", () => {
			render(<InfoButton rounding="md">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("rounded-md");
		});
		it("Renders with large rounding", () => {
			render(<InfoButton rounding="lg">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("rounded-lg");
		});
		it("Renders with full rounding", () => {
			render(<InfoButton rounding="full">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("rounded-full");
		});
	});

	describe("InfoButton Component Size and Shape", () => {
		it("Renders with xs square", () => {
			render(<InfoButton size="xs" shape="square">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("p-0");
		});
		it("Renders with sm square", () => {
			render(<InfoButton size="sm" shape="square">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("p-1");
		});
		it("Renders with md square", () => {
			render(<InfoButton size="md" shape="square">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("p-2");
		});
		it("Renders with lg square", () => {
			render(<InfoButton size="lg" shape="square">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("p-3");
		});
		it("Renders with xl square", () => {
			render(<InfoButton size="xl" shape="square">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("p-4");
		});
		it("Renders with xs rectangle", () => {
			render(<InfoButton size="xs" shape="rectangle">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("px-1", "py-0");
		});
		it("Renders with sm rectangle", () => {
			render(<InfoButton size="sm" shape="rectangle">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("px-2", "py-1");
		});
		it("Renders with md rectangle", () => {
			render(<InfoButton size="md" shape="rectangle">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("px-4", "py-2");
		});
		it("Renders with lg rectangle", () => {
			render(<InfoButton size="lg" shape="rectangle">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("px-6", "py-3");
		});
		it("Renders with xl rectangle", () => {
			render(<InfoButton size="xl" shape="rectangle">{buttonText}</InfoButton>);

			const button = screen.getByTestId("mattrixwv-info-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("px-8", "py-4");
		});
	});
});

describe("InfoButton Component Disabled", () => {
	it("Render with defaults when disabled", () => {
		render(<InfoButton disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		//Check button requirements
		expect(button).toBeInTheDocument();
		expect(button).toHaveTextContent(buttonText);
		//Classes
		expect(button).toHaveClass("rounded-lg");
		expect(button).toHaveClass("px-4", "py-2");
		expect(button).toHaveClass("border");
		//Disabled state
		expect(button).not.toHaveClass("cursor-pointer");
		expect(button).toHaveClass("bg-info-light/80");
		expect(button).toHaveClass("border-info-light/80");
		expect(button).toHaveClass("text-black");
	});
	it("Renders with custom className when disabled", () => {
		const customClass = "custom-info-button-class";

		render(<InfoButton className={customClass} disabled>{buttonText}</InfoButton>);

		//Check button requirements
		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass(customClass);
	});
	it("Renders with aria-label when disabled", () => {
		const ariaLabel = "Info Button Aria Label";

		render(<InfoButton aria-label={ariaLabel} disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveAttribute("aria-label", ariaLabel);
	});
	it("Does not trigger onClick handler when disabled", async () => {
		const handleClick = vi.fn();

		render(<InfoButton onClick={handleClick} disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();

		await userEvent.click(button);
		expect(handleClick).toHaveBeenCalledTimes(0);
	});
});

describe("InfoButton Component Variants", () => {
	it("Renders with standard variant", () => {
		render(<InfoButton variant="standard">{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-info", "active:bg-info-dark");
		expect(button).toHaveClass("border", "border-info", "active:border-info-dark");
		expect(button).toHaveClass("text-black");
	});
	it("Renders with outline variant", () => {
		render(<InfoButton variant="outline">{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border", "border-info", "active:border-info-dark");
		expect(button).toHaveClass("text-info", "active:text-info-dark");
	});
	it("Renders with outline-ghost variant", () => {
		render(<InfoButton variant="outline-ghost">{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent", "hover:bg-info", "active:bg-info-dark");
		expect(button).toHaveClass("border", "border-info", "active:border-info-dark");
		expect(button).toHaveClass("text-info", "hover:text-black", "active:text-black");
	});
	it("Renders with ghost variant", () => {
		render(<InfoButton variant="ghost">{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent", "hover:bg-info", "active:bg-info-dark");
		expect(button).toHaveClass("border-none");
		expect(button).toHaveClass("text-info", "hover:text-black", "active:text-black");
	});
	it("Renders with icon variant", () => {
		render(<InfoButton variant="icon">{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border-none");
		expect(button).toHaveClass("text-info", "active:text-info-dark");
	});
});

describe("InfoButton Component Variants Disabled", () => {
	it("Renders with standard variant when disabled", () => {
		render(<InfoButton variant="standard" disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-info-light/80");
		expect(button).toHaveClass("border", "border-info-light/80");
		expect(button).toHaveClass("text-black");
	});
	it("Renders with outline variant when disabled", () => {
		render(<InfoButton variant="outline" disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border", "border-info-light/80");
		expect(button).toHaveClass("text-info-light/80");
	});
	it("Renders with outline-ghost variant when disabled", () => {
		render(<InfoButton variant="outline-ghost" disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border", "border-info-light/80");
		expect(button).toHaveClass("text-info-light/80");
	});
	it("Renders with ghost variant when disabled", () => {
		render(<InfoButton variant="ghost" disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border-none");
		expect(button).toHaveClass("text-info-light/80");
	});
	it("Renders with icon variant when disabled", () => {
		render(<InfoButton variant="icon" disabled>{buttonText}</InfoButton>);

		const button = screen.getByTestId("mattrixwv-info-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border-none");
		expect(button).toHaveClass("text-info-light/80");
	});
});
