"use client";
import { jsx } from "react/jsx-runtime";
import { forwardRef } from "react";
import NextLink from "next/link";
import { useIsPagesRouter } from "../../hooks/use-is-pages-router";
const isValidHref = (href) => {
  try {
    const bases = ["http://n", "https://n"];
    bases.forEach((base) => new URL(href, base));
  } catch (_) {
    return false;
  }
  return true;
};
const Link = forwardRef(function Link2({ linkType, href, ...props }, ref) {
  const useNextLink = href != null && (linkType === "OPEN_PAGE" || linkType === "OPEN_URL" && isValidHref(href));
  const isPagesRouter = useIsPagesRouter();
  if (useNextLink) {
    return /* @__PURE__ */ jsx(
      NextLink,
      {
        ...props,
        ref,
        href,
        ...isPagesRouter ? { locale: false } : {},
        legacyBehavior: false
      }
    );
  }
  return /* @__PURE__ */ jsx("a", { ...props, ref, href });
});
export {
  Link
};
//# sourceMappingURL=link.js.map