"use strict";
var import_Link = require("../Link.css");
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const kit_Theme_UI = require("./Theme/UI.cjs");
require("./Theme/themeUtils.cjs");
require("./Theme/themes.cjs");
const kit_Icon = require("./Icon.cjs");
const base = "Link_base_1c6b6";
const inherit = "Link_inherit_1c6b6";
const disabled = "Link_disabled_1c6b6";
const tiny = "Link_tiny_1c6b6";
const small = "Link_small_1c6b6";
const medium = "Link_medium_1c6b6";
const large = "Link_large_1c6b6";
const css = {
  base,
  inherit,
  disabled,
  tiny,
  small,
  medium,
  large
};
const Link = ({
  size,
  onClick,
  href,
  rel,
  disabled: disabled2,
  external,
  ...props
}) => {
  const {
    themeSettings: { className: themeClass }
  } = kit_Theme_UI.useTheme();
  const classes = [css.base, themeClass];
  if (disabled2)
    classes.push(css.disabled);
  if (size)
    classes.push(css[size]);
  const ref = React.useRef(null);
  const onKeyDown = (e) => {
    var _a;
    if (e.key === "Enter")
      (_a = ref.current) == null ? void 0 : _a.click();
  };
  const content = React.useMemo(
    () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
      /* @__PURE__ */ jsxRuntime.jsx("span", { children: props.children }),
      external ? /* @__PURE__ */ jsxRuntime.jsx(kit_Icon.default, { name: "popout", size: "small", title: "link" }) : null
    ] }),
    [props.children, external]
  );
  if (disabled2) {
    return /* @__PURE__ */ jsxRuntime.jsx("span", { className: classes.join(" "), children: content });
  }
  return /* @__PURE__ */ jsxRuntime.jsx(
    "a",
    {
      "aria-label": href,
      className: classes.join(" "),
      href,
      ref,
      rel,
      tabIndex: 0,
      onClick: (e) => {
        e.stopPropagation();
        onClick == null ? void 0 : onClick(e);
      },
      onKeyDown,
      children: content
    }
  );
};
module.exports = Link;
