"use strict";
const jsxRuntime = require("react/jsx-runtime");
const clsx = require("clsx");
const React = require("react");
const styles_lib_css_atoms_atoms_cjs = require("../../css/atoms/atoms.cjs");
const styles_lib_components_Box_BackgroundContext_cjs = require("../Box/BackgroundContext.cjs");
const sideEffects_lib_components_BraidProvider_BraidProvider_cjs = require("../../../../side-effects/lib/components/BraidProvider/BraidProvider.cjs");
const styles_lib_components_Heading_Heading_cjs = require("../Heading/Heading.cjs");
const styles_lib_components_Accordion_AccordionItem_cjs = require("../Accordion/AccordionItem.cjs");
const styles_lib_components_private_AvoidWidowIcon_AvoidWidowIcon_cjs = require("../private/AvoidWidowIcon/AvoidWidowIcon.cjs");
const styles_lib_components_Accordion_Accordion_cjs = require("../Accordion/Accordion.cjs");
const styles_lib_components_private_touchable_virtualTouchable_cjs = require("../private/touchable/virtualTouchable.cjs");
const styles_lib_components_TextLink_TextLink_css_cjs = require("./TextLink.css.cjs");
const styles_lib_css_typography_css_cjs = require("../../css/typography.css.cjs");
const _interopDefaultCompat = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const clsx__default = /* @__PURE__ */ _interopDefaultCompat(clsx);
const isPlainBackground = (backgroundContext, contrast) => contrast === "light" && (backgroundContext === "body" || backgroundContext === "surface" || backgroundContext === "neutralLight") || contrast === "dark" && (backgroundContext === "bodyDark" || backgroundContext === "surfaceDark" || backgroundContext === "neutral");
const useLinkStyles = ({
  reset = "a",
  weight,
  showVisited = false,
  hitArea = "standard"
}) => {
  const backgroundLightness = styles_lib_components_Box_BackgroundContext_cjs.useBackgroundLightness();
  const backgroundContext = styles_lib_components_Box_BackgroundContext_cjs.useBackground();
  const textContext = React.useContext(styles_lib_components_Accordion_AccordionItem_cjs.TextContext);
  const headingContext = React.useContext(styles_lib_components_Heading_Heading_cjs.HeadingContext);
  const isWeakDueToTextTone = !headingContext && (textContext == null ? void 0 : textContext.tone) !== "neutral" && (textContext == null ? void 0 : textContext.tone) !== "secondary";
  const linkStyles = weight === "weak" || isWeakDueToTextTone ? styles_lib_components_TextLink_TextLink_css_cjs.weakLink : [
    isPlainBackground(backgroundContext.lightMode, "light") || weight === "regular" ? styles_lib_components_TextLink_TextLink_css_cjs.regularLinkLightMode[backgroundLightness.lightMode] : styles_lib_components_TextLink_TextLink_css_cjs.weakLink,
    isPlainBackground(backgroundContext.darkMode, "dark") || weight === "regular" ? styles_lib_components_TextLink_TextLink_css_cjs.regularLinkDarkMode[backgroundLightness.darkMode] : styles_lib_components_TextLink_TextLink_css_cjs.weakLink
  ];
  return clsx__default.default(
    styles_lib_components_TextLink_TextLink_css_cjs.base,
    linkStyles,
    weight !== "weak" ? styles_lib_css_typography_css_cjs.fontWeight.medium : void 0,
    showVisited ? [
      styles_lib_components_TextLink_TextLink_css_cjs.visitedLightMode[backgroundLightness.lightMode],
      styles_lib_components_TextLink_TextLink_css_cjs.visitedDarkMode[backgroundLightness.darkMode]
    ] : "",
    reset !== false ? styles_lib_css_atoms_atoms_cjs.atoms({
      reset: typeof reset === "string" ? reset : "a"
    }) : null,
    styles_lib_css_atoms_atoms_cjs.atoms({
      cursor: "pointer"
    }),
    hitArea === "large" && styles_lib_components_private_touchable_virtualTouchable_cjs.virtualTouchable()
  );
};
const TextLinkContent = ({
  icon,
  iconPosition = "leading",
  children
}) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
  icon && iconPosition === "leading" ? /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_private_AvoidWidowIcon_AvoidWidowIcon_cjs.AvoidWidowIcon, { iconPosition, children: icon }) : null,
  children,
  icon && iconPosition === "trailing" ? /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_private_AvoidWidowIcon_AvoidWidowIcon_cjs.AvoidWidowIcon, { iconPosition, children: icon }) : null
] });
const TextLink = React.forwardRef(
  ({
    weight,
    showVisited,
    hitArea,
    data,
    icon,
    children,
    iconPosition,
    ...restProps
  }, ref) => {
    const LinkComponent = sideEffects_lib_components_BraidProvider_BraidProvider_cjs.useLinkComponent(ref);
    const classes = useLinkStyles({
      weight,
      showVisited,
      hitArea
    });
    return /* @__PURE__ */ jsxRuntime.jsx(
      LinkComponent,
      {
        ref,
        ...restProps,
        className: classes,
        ...styles_lib_components_Accordion_Accordion_cjs.buildDataAttributes({ data, validateRestProps: false }),
        children: /* @__PURE__ */ jsxRuntime.jsx(TextLinkContent, { icon, iconPosition, children })
      }
    );
  }
);
TextLink.displayName = "TextLink";
exports.TextLink = TextLink;
exports.TextLinkContent = TextLinkContent;
exports.useLinkStyles = useLinkStyles;
