import type { RadioButtonProps } from "$/types/InputTypes";
import { Radio } from "@headlessui/react";
import clsx from "clsx";


export default function RadioButton({
	id = crypto.randomUUID().replaceAll("-", ""),
	className,
	labelClassName,
	size = "sm",
	value,
	disabled,
	children
}: Readonly<RadioButtonProps>){
	return (
		<Radio
			id={id}
			value={value}
			className={clsx(
				"group",
				"flex flex-row items-center justify-center gap-x-2",
				"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
				{
					"cursor-pointer": !disabled,
					"cursor-not-allowed": disabled
				}
			)}
			disabled={disabled}
			aria-labelledby={`${id}Label`}
		>
			<div
				className={clsx(
					"rounded-full not-group-data-checked:border",
					className,
					{
						"": size === "none",
						"size-3": size === "xs",
						"size-4": size === "sm",
						"size-5": size === "md",
						"size-6": size === "lg",
						"size-7": size === "xl"
					}
				)}
			/>
			{
				children &&
				<span
					id={`${id}Label`}
					className={labelClassName}
				>
					{children}
				</span>
			}
		</Radio>
	);
}
