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


const buttonText = "Dark Button";


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

		const button = screen.getByTestId("mattrixwv-dark-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-dark", "active:bg-dark-mid");
		expect(button).toHaveClass("border-dark", "active:border-dark-mid");
		expect(button).toHaveClass("text-white");
	});

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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