import type { SerializedLinkNode } from "@payloadcms/richtext-lexical";

export const internalDocToHref = ({
	linkNode,
}: {
	linkNode: SerializedLinkNode;
}) => {
	// biome-ignore lint/style/noNonNullAssertion: safe
	const { value, relationTo } = linkNode.fields.doc!;

	const slug =
		typeof value !== "string" && typeof value !== "number" && value.slug;

	if (relationTo === "posts") {
		return `/posts/${slug}`;
	} else if (relationTo === "users") {
		return `/users/${slug}`;
	} else {
		return `/${slug}`;
	}
};
