---
import { sanitizeHref } from "../../utils/url.js";

/**
 * Portable Text Link mark component
 *
 * Receives node with markDef containing link details from astro-portabletext
 */
export interface Props {
	node: {
		markDef: {
			_type: "link";
			_key: string;
			href: string;
			blank?: boolean;
		};
	};
}

const { node } = Astro.props;
const href = sanitizeHref(node?.markDef?.href);
const blank = node?.markDef?.blank;
---

<a
	href={href}
	target={blank ? "_blank" : undefined}
	rel={blank ? "noopener noreferrer" : undefined}
>
	<slot />
</a>
