// packages/components/src/external-link/index.tsx
import clsx from "clsx";
import { __ } from "@wordpress/i18n";
import { forwardRef } from "@wordpress/element";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
function UnforwardedExternalLink(props, ref) {
  const {
    href,
    children,
    className,
    rel = "",
    ...additionalProps
  } = props;
  const optimizedRel = [...new Set([...rel.split(" "), "external", "noreferrer", "noopener"].filter(Boolean))].join(" ");
  const classes = clsx("components-external-link", className);
  const isInternalAnchor = !!href?.startsWith("#");
  const onClickHandler = (event) => {
    if (isInternalAnchor) {
      event.preventDefault();
    }
    if (props.onClick) {
      props.onClick(event);
    }
  };
  return (
    /* eslint-disable react/jsx-no-target-blank */
    /* @__PURE__ */ _jsxs("a", {
      ...additionalProps,
      className: classes,
      href,
      onClick: onClickHandler,
      target: "_blank",
      rel: optimizedRel,
      ref,
      children: [/* @__PURE__ */ _jsx("span", {
        className: "components-external-link__contents",
        children
      }), /* @__PURE__ */ _jsx("span", {
        className: "components-external-link__icon",
        "aria-label": (
          /* translators: accessibility text */
          __("(opens in a new tab)")
        ),
        children: "\u2197"
      })]
    })
  );
}
var ExternalLink = forwardRef(UnforwardedExternalLink);
var external_link_default = ExternalLink;
export {
  ExternalLink,
  external_link_default as default
};
//# sourceMappingURL=index.js.map
