import type { JSX } from "solid-js";
import { splitProps } from "solid-js";
import type { LinkProps } from "./link.props";
export type { LinkProps } from "./link.props";

/**
 * An accessible link component.
 * When disabled, removes href and adds aria-disabled="true" with role="link".
 */
export function Link(props: LinkProps): JSX.Element {
	const [local, rest] = splitProps(props, ["href", "disabled", "children"]);

	return (
		<a
			href={local.disabled ? undefined : local.href}
			role="link"
			aria-disabled={local.disabled ? "true" : undefined}
			data-disabled={local.disabled || undefined}
			{...rest}
		>
			{local.children}
		</a>
	);
}
