import { renderTypography } from "../components/typography/renderTypography.js";
import { useEffect, useRef, useState } from "react";
import { jsx } from "@emotion/react/jsx-runtime";
//#region src/utils/NextLink.tsx
function NextLink({ href, text, children, id, target: targetProp, typography }) {
	const NextLinkRef = useRef(null);
	const [ready, setReady] = useState(false);
	const isExternal = href.startsWith("http");
	const target = targetProp ? targetProp : isExternal ? "_blank" : void 0;
	useEffect(() => {
		(async () => {
			try {
				NextLinkRef.current = (await import("next/link.js")).default;
			} catch {}
			setReady(true);
		})();
	});
	const InternalNextLink = NextLinkRef.current;
	let content = children;
	if (text) content = typography ? renderTypography(typography.type, {
		size: typography.size,
		color: typography.color,
		children: text
	}) : text;
	if (!ready || !InternalNextLink) return /* @__PURE__ */ jsx("a", {
		href,
		target,
		id,
		children: content
	});
	return /* @__PURE__ */ jsx(InternalNextLink, {
		href,
		target,
		id,
		children: content
	});
}
//#endregion
export { NextLink };
