import {
  renderTypography
} from "./chunk-KAMBSKAE.js";
import {
  __async
} from "./chunk-W7FAWX6T.js";

// src/utils/NextLink.tsx
import {
  useEffect,
  useRef,
  useState
} from "react";
import { jsx } from "@emotion/react/jsx-runtime";
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(() => {
    void (() => __async(this, null, function* () {
      try {
        const nextLinkModule = yield import("next/link.js");
        NextLinkRef.current = nextLinkModule.default;
      } catch (e) {
      }
      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 });
}

export {
  NextLink
};
