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


const buttonText = "Danger Button";


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

		const button = screen.getByTestId("mattrixwv-danger-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-red-600", "hover:bg-red-700", "active:bg-red-800");
		expect(button).toHaveClass("border-red-600", "hover:border-red-700", "active:border-red-800");
		expect(button).toHaveClass("text-white");
	});
	it("Renders with custom className", () => {
		const customClass = "custom-danger-button-class";

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

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

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

		const button = screen.getByTestId("mattrixwv-danger-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveAttribute("aria-label", ariaLabel);
	});
	it("Renders with onClick handler", async () => {
		const handleClick = vi.fn();

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

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

		await userEvent.click(button);
		expect(handleClick).toHaveBeenCalledTimes(1);
	});
	describe("DangerButton Component Rounding", () => {
		it("Renders with small rounding", () => {
			render(<DangerButton rounding="sm">{buttonText}</DangerButton>);

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

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

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

			const button = screen.getByTestId("mattrixwv-danger-button");
			expect(button).toBeInTheDocument();
			expect(button).toHaveClass("rounded-full");
		});
	});
	describe("DangerButton Component Size and Shape", () => {
		it("Renders with xs square", () => {
			render(<DangerButton size="xs" shape="square">{buttonText}</DangerButton>);

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

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

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

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

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

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

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

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

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

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

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

		const button = screen.getByTestId("mattrixwv-danger-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-red-400/80");
		expect(button).toHaveClass("border-red-400/80");
		expect(button).toHaveClass("text-white");
	});
	it("Renders with custom className when disabled", () => {
		const customClass = "custom-danger-button-class";

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

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

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

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

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

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

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

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

		const button = screen.getByTestId("mattrixwv-danger-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-red-600", "hover:bg-red-700", "active:bg-red-800");
		expect(button).toHaveClass("border", "border-red-600", "hover:border-red-700", "active:border-red-800");
		expect(button).toHaveClass("text-white");
	});
	it("Renders with outline variant", () => {
		render(<DangerButton variant="outline">{buttonText}</DangerButton>);

		const button = screen.getByTestId("mattrixwv-danger-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border", "border-red-600", "hover:border-red-700", "active:border-red-800");
		expect(button).toHaveClass("text-red-600", "hover:text-red-700", "active:text-red-800");
	});
	it("Renders with outline-ghost variant", () => {
		render(<DangerButton variant="outline-ghost">{buttonText}</DangerButton>);

		const button = screen.getByTestId("mattrixwv-danger-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent", "hover:bg-red-600", "active:bg-red-700");
		expect(button).toHaveClass("border", "border-red-600", "hover:border-red-600", "active:border-red-700");
		expect(button).toHaveClass("text-red-600", "hover:text-white", "active:text-white");
	});
	it("Renders with ghost variant", () => {
		render(<DangerButton variant="ghost">{buttonText}</DangerButton>);

		const button = screen.getByTestId("mattrixwv-danger-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent", "hover:bg-red-600", "active:bg-red-700");
		expect(button).toHaveClass("border-none");
		expect(button).toHaveClass("text-red-600", "hover:text-white", "active:text-white");
	});
	it("Renders with icon variant", () => {
		render(<DangerButton variant="icon">{buttonText}</DangerButton>);

		const button = screen.getByTestId("mattrixwv-danger-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-transparent");
		expect(button).toHaveClass("border-none");
		expect(button).toHaveClass("text-red-600", "hover:text-red-700", "active:text-red-800");
	});
});

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

		const button = screen.getByTestId("mattrixwv-danger-button");
		expect(button).toBeInTheDocument();
		expect(button).toHaveClass("bg-red-400/80");
		expect(button).toHaveClass("border", "border-red-400/80");
		expect(button).toHaveClass("text-white");
	});
	it("Renders with outline variant when disabled", () => {
		render(<DangerButton variant="outline" disabled>{buttonText}</DangerButton>);

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

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

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

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