import { jsx } from "react/jsx-runtime";
import { forwardRef } from "react";
import { Link as Link$1 } from "@netlify/ui";
const isLinkInternal = (href) => {
  try {
    const parsed = new URL(href);
    return parsed.origin === "https://app.netlifystg.com" || parsed.origin === "https://app.netlify.com" || parsed.origin === "http://localhost:8888";
  } catch {
    return false;
  }
};
const getLinkType = ({
  external,
  href,
  internal
}) => {
  if (href === void 0) {
    return "none";
  }
  const isDetectedInternal = isLinkInternal(href);
  if (external === true) {
    return "external";
  }
  if (internal === true) {
    return "internal";
  }
  if (isDetectedInternal) {
    return "internal";
  }
  return "external";
};
const Link = forwardRef(({ children, href, internal, external, ...otherProps }, ref) => {
  const linkType = getLinkType({ href, internal, external });
  return /* @__PURE__ */ jsx(
    Link$1,
    {
      ...otherProps,
      action: linkType === "internal" ? true : void 0,
      external: linkType === "external" ? true : void 0,
      href,
      ref,
      showExternalIcon: linkType === "external" ? true : void 0,
      children
    }
  );
});
export {
  Link
};
//# sourceMappingURL=Link.js.map
