import { jsx as E } from "react/jsx-runtime";
import R, { useRef as V, useState as W, useEffect as k } from "react";
import { c as z } from "../../index-BtlgVD4m.js";
import { fontWeightVariants as A } from "./types/FontWeightVariant.js";
import { textColorVariants as O } from "./types/TextColorVariant.js";
import { typographyVariants as H } from "./types/TypographyVariant.js";
import { textAlignVariants as N } from "./types/TextAlignVariant.js";
import P from "../tooltip/Tooltip.js";
const _ = ["body", "large", "small", "muted", "lead", "xs"], $ = ({
  type: o = "body",
  isStriked: u = !1,
  align: p = "start",
  weight: a,
  breakWord: c = !0,
  truncate: t = !1,
  maxLines: s,
  id: b = null,
  children: n,
  color: d,
  isLeading: v = !0,
  as: m
}) => {
  const l = V(null), [h, w] = W(!1), i = t && s !== void 0 && s >= 1;
  k(() => {
    if (!t || !l.current)
      return;
    const e = l.current, r = () => {
      if (e) {
        const C = i && e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
        w(C);
      }
    };
    r();
    const f = new ResizeObserver(() => {
      r();
    });
    return f.observe(e), window.addEventListener("resize", r), () => {
      f.disconnect(), window.removeEventListener("resize", r);
    };
  }, [t, n, i]);
  const T = m || (_.includes(o) ? "p" : o === "inline-code" ? "code" : o), g = i ? `line-clamp-[${s}]` : null, x = z(
    N[p],
    H[o],
    d && O[d],
    a && A[a],
    u && "line-through",
    t ? `${m === "span" ? "w-fit" : "w-full"}${i ? "" : " truncate"}` : c && "break-words",
    g,
    // Honor breakWord for multi-line truncation to prevent horizontal clipping of long URLs/tokens
    i && c && "break-words",
    !v && "leading-none"
  ), y = R.createElement(
    T,
    {
      id: b,
      className: x,
      style: i ? { overflow: "hidden", display: "-webkit-box", WebkitBoxOrient: "vertical", WebkitLineClamp: s } : void 0,
      ref: t ? l : void 0
    },
    n
  );
  return /* @__PURE__ */ E(P, { content: n, hidden: !(t && h && typeof n == "string"), delayDuration: 300, asChild: !0, children: y });
};
$.displayName = "Text";
export {
  $ as default
};
//# sourceMappingURL=Text.js.map
