import { jsx as i, jsxs as k, Fragment as ye } from "react/jsx-runtime";
/* empty css                */
import { classNames as xe } from "./index-classNames.js";
import { parseCssVariable as ne } from "./index-css-variables-parser.js";
import { sanitizeHTMLToReactNode as C } from "./index-sanitize-html.js";
import { translationHelper as l } from "./index-translation-helper.js";
import { translationService as T } from "./index-translation.service.js";
import { rcWindow as ae } from "./index-window.store.js";
import { applyWordAnimation as be } from "./index-text-animate-words-style.js";
import { parseFullLinks as ke } from "./index-text-links-parser.js";
import { TextWrapBalancer as V } from "./index-TextWrapBalancer.js";
import "./index-html-react-parser.js";
import * as w from "react";
import { useState as z, useMemo as ie } from "react";
import { s as se } from "./index-server.browser.js";
import { childrenAsText as H } from "./index-child-to-text.js";
import Ce from "./index-_virtual.js";
var K;
(function(n) {
  n.heading1 = "heading-1", n.heading2 = "heading-2", n.heading3 = "heading-3", n.heading4 = "heading-4", n.textIntro = "text-intro", n.text = "text", n.textHelp = "text-help", n.textCaption = "text-caption", n.display1 = "display-1", n.display2 = "display-2";
})(K || (K = {}));
var d;
(function(n) {
  n.regular = "regular", n.medium = "medium", n.bold = "bold";
})(d || (d = {}));
const Ke = (n) => {
  const {
    type: m = K.text,
    children: o,
    textTight: le = !1,
    maxWidth: oe,
    maxChar: u,
    // Updated prop name
    maxLines: R,
    textAlign: I,
    fontWeight: g = d.regular,
    fontSize: O,
    textWrap: M = "wrap",
    wordBreak: P = "initial",
    replacements: S,
    context: F = "one",
    testId: v,
    translate: y = !0,
    className: U = "",
    color: _,
    display: q = "block",
    uppercase: ce = !1,
    links: f,
    balanced: W,
    disabled: de,
    capitalize: fe = !1,
    isBlurred: pe = !1,
    seeMore: a = !1,
    ellipsis: he,
    allowNewLines: D = !1,
    animateWords: G = void 0,
    highlightWords: x,
    highlightColor: J,
    highlightMode: E = "background",
    highlightCaseInsensitive: me = !1,
    ...L
  } = n, Q = ae.translationsWritingStyle ? ae.translationsWritingStyle : "personal";
  let t = o;
  const [X, ue] = z(!1), [N, ge] = z(!1), [Y, Z] = z(!1), ee = (e) => l.shouldTrackTranslations ? e.wasTranslated : l.shouldTrackTranslationKeys ? e.hasTranslationKey : !1;
  let p = null, b = "";
  typeof o == "string" ? b = o : b = H(o);
  const c = typeof a == "object" && (a.seeMoreVisible === !0 || a.seeMoreVisible === void 0);
  if (p = ie(() => {
    const e = T.get(b, S, F, Q), r = ke(f, e.value);
    return u && typeof r == "string" && (e.value.length > u ? Z(!0) : Z(!1)), {
      value: r,
      fixedValue: r,
      wasTranslated: e.wasTranslated
      // include other properties from the translation object as needed
    };
  }, [S, o, F, Q, f]), t = y ? Ce(p.value, {
    htmlparser2: {
      lowerCaseTags: !1
    }
  }) : T.justReplace(b, S), typeof t == "string" && (x != null && x.length)) {
    const e = {
      backgroundColor: E === "background" ? J : void 0,
      color: E === "text" ? J : void 0,
      fontWeight: E === "bold" ? "bold" : void 0
    };
    x.forEach((r) => {
      if (me) {
        const s = new RegExp(r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi"), h = t.match(s);
        h && h.forEach((re) => {
          t = t.replace(re, se.renderToString(i("span", {
            style: e,
            children: re
          })));
        });
      } else
        t = t.replace(r, se.renderToString(i("span", {
          style: e,
          children: r
        })));
    });
  }
  ie(() => {
    y && (l.shouldTrackTranslations || l.shouldTrackTranslationKeys) && (ue(ee(p)), ee(p) ? l.addTranslated(H(o)) : l.addUntranslated(H(o)));
  }, [p, l.shouldTrackTranslations, l.shouldTrackTranslationKeys]);
  const j = () => {
    let e = `rc-text ${m}`;
    return M && (e += ` text-${M}`), P && (e += ` text-${P}`), le && (e += " text-tight"), pe && (e += " text-isBlurred"), D && (e += " notranslate"), y || (e += " notranslate"), (l.shouldTrackTranslations || l.shouldTrackTranslationKeys) && (X || (e += " not-translated"), X && (e += " was-translated"), y || (e += " do-not-translate")), ce && (e += " uppercase"), fe && (e += " text-capitalize"), U && (e += ` ${U}`), e;
  }, $ = () => {
    const e = {};
    return de && (e.color = ne("--n300")), _ && (e.color = ne(_)), g && (g === d.regular && (e.fontWeight = "normal"), g === d.medium && (e.fontWeight = 500), g === d.bold && (e.fontWeight = "bold")), O && (e.fontSize = O), I && (e.textAlign = I), he && (e.whiteSpace = M === "wrap" ? "unset" : "nowrap", e.overflow = "hidden", e.textOverflow = "ellipsis", e.wordBreak = n.wordBreak || "break-word", e.maxWidth = oe || "100%"), q && (e.display = q), e;
  }, A = () => {
    typeof a == "object" && !c || ge((e) => !e);
  }, te = (e) => i("b", {
    style: {
      cursor: "pointer"
    },
    children: T.get(e).value
  }), B = () => {
    if (D && typeof t == "string" && !a && (t = t.replaceAll(`
`, "<br>")), typeof t == "string") {
      const e = C(t);
      if (typeof a == "boolean" && a) {
        const r = te(N ? "See Less" : "See More"), s = N ? t : `${t.slice(0, u)}...`;
        Y && (e.children = k(ye, {
          children: [C(s).children, " ", i("a", {
            onClick: A,
            children: r
          })]
        }));
      } else if (
        //@ts-ignore
        c && //@ts-ignore
        a.seeMoreContent && R
      )
        a && (e.children = k("span", {
          className: "see-more",
          style: {
            WebkitLineClamp: R
          },
          children: [C(t).children, t.length > 100 && i("span", {
            className: "see-more-content",
            children: (
              //@ts-ignore
              c && a.seeMoreContent
            )
          })]
        }));
      else if (c && //@ts-ignore
      a.seeMoreContent && //@ts-ignore
      a.seeLessContent || typeof a == "object" && a.seeMoreVisible === !1)
        if (N)
          a && (e.children = k("span", {
            onClick: A,
            children: [
              C(t).children,
              " ",
              // @ts-ignore
              c && a.seeLessContent
            ]
          }));
        else {
          const r = typeof t == "string" ? `${t.slice(0, u)}...` : t;
          Y && (e.children = k("span", {
            onClick: A,
            children: [
              // @ts-ignore
              r,
              c && //@ts-ignore
              a.seeMoreContent
            ]
          }));
        }
      return G && (e.children = be(t, G)), e;
    }
    return t && typeof t == "object" && //@ts-ignore
    typeof t[0] == "object" && f && typeof f == "object" && t.forEach((e, r) => {
      if (e.type === "a") {
        const s = f[e.props.children], h = T.get(s.text);
        s.href && ((t ?? [])[r] = w.createElement("a", {
          href: s.href,
          key: r,
          target: s.target,
          style: {
            cursor: "pointer"
          }
        }, w.createElement("em", {}, h.value))), s.onClick && ((t ?? [])[r] = w.createElement("a", {
          onClick: s.onClick,
          key: r,
          role: "link",
          style: {
            cursor: "pointer"
          }
        }, w.createElement("em", {}, h.value)));
      }
    }), {
      children: t
    };
  };
  if (m.indexOf("heading") >= 0) {
    const r = `h${m.split("-")[1]}`;
    return i(V, {
      balanced: W,
      children: i(r, {
        "data-testid": v,
        className: j(),
        style: $(),
        ...B(),
        ...L
      })
    });
  }
  return m.indexOf("display") >= 0 ? i(V, {
    balanced: W,
    children: i("h1", {
      "data-testid": v,
      className: j(),
      style: $(),
      ...B(),
      ...L
    })
  }) : i(V, {
    balanced: W,
    children: i("span", {
      "data-testid": v,
      className: xe("paragraph", j()),
      style: $(),
      ...B(),
      ...L
    })
  });
};
export {
  d as FontWeights,
  Ke as Text,
  K as TextTypes
};
