import je from "../../../../@ant-design/icons/es/icons/CheckOutlined.mjs";
import We from "../../../../@ant-design/icons/es/icons/CopyOutlined.mjs";
import Ae from "../../../../@ant-design/icons/es/icons/EditOutlined.mjs";
import te from "../../../../classnames/index.mjs";
import Ve from "../../../../copy-to-clipboard/index.mjs";
import Be from "../../../../rc-resize-observer/es/index.mjs";
import De from "../../../../rc-util/es/Children/toArray.mjs";
import Fe from "../../../../rc-util/es/hooks/useLayoutEffect.mjs";
import Je from "../../../../rc-util/es/hooks/useMergedState.mjs";
import He from "../../../../rc-util/es/omit.mjs";
import { composeRef as Ue } from "../../../../rc-util/es/ref.mjs";
import * as o from "react";
import { isStyleSupport as oe } from "../../../../rc-util/es/Dom/styleChecker.mjs";
import ie from "../../_util/transButton.mjs";
import "../../config-provider/index.mjs";
import qe from "../../locale/useLocale.mjs";
import ne from "../../tooltip/index.mjs";
import Ge from "../Editable.mjs";
import Ke from "../Typography.mjs";
import B from "../hooks/useMergedConfig.mjs";
import Qe from "../hooks/useUpdatedEffect.mjs";
import Xe from "./Ellipsis.mjs";
import Ye from "./EllipsisTooltip.mjs";
import { ConfigContext as Ze } from "../../config-provider/context.mjs";
var et = globalThis && globalThis.__rest || function(i, y) {
  var f = {};
  for (var a in i)
    Object.prototype.hasOwnProperty.call(i, a) && y.indexOf(a) < 0 && (f[a] = i[a]);
  if (i != null && typeof Object.getOwnPropertySymbols == "function")
    for (var p = 0, a = Object.getOwnPropertySymbols(i); p < a.length; p++)
      y.indexOf(a[p]) < 0 && Object.prototype.propertyIsEnumerable.call(i, a[p]) && (f[a[p]] = i[a[p]]);
  return f;
};
function tt(i, y) {
  let {
    mark: f,
    code: a,
    underline: p,
    delete: S,
    strong: h,
    keyboard: O,
    italic: w
  } = i, C = y;
  function s(P, $) {
    $ && (C = /* @__PURE__ */ o.createElement(P, {}, C));
  }
  return s("strong", h), s("u", p), s("del", S), s("code", a), s("mark", f), s("kbd", O), s("i", w), C;
}
function R(i, y, f) {
  return i === !0 || i === void 0 ? y : i || f && y;
}
function le(i) {
  return i === !1 ? [!1, !1] : Array.isArray(i) ? i : [i];
}
const ot = "...", it = /* @__PURE__ */ o.forwardRef((i, y) => {
  var f, a, p;
  const {
    prefixCls: S,
    className: h,
    style: O,
    type: w,
    disabled: C,
    children: s,
    ellipsis: P,
    editable: $,
    copyable: se,
    component: D,
    title: k
  } = i, re = et(i, ["prefixCls", "className", "style", "type", "disabled", "children", "ellipsis", "editable", "copyable", "component", "title"]), {
    getPrefixCls: ae,
    direction: F
  } = o.useContext(Ze), [n] = qe("Text"), z = o.useRef(null), J = o.useRef(null), u = ae("typography", S), ce = He(re, ["mark", "code", "delete", "underline", "strong", "keyboard", "italic"]), [M, l] = B($), [j, pe] = Je(!1, {
    value: l.editing
  }), {
    triggerType: H = ["icon"]
  } = l, W = (e) => {
    var t;
    e && ((t = l.onStart) === null || t === void 0 || t.call(l)), pe(e);
  };
  Qe(() => {
    var e;
    j || (e = J.current) === null || e === void 0 || e.focus();
  }, [j]);
  const U = (e) => {
    e == null || e.preventDefault(), W(!0);
  }, de = (e) => {
    var t;
    (t = l.onChange) === null || t === void 0 || t.call(l, e), W(!1);
  }, fe = () => {
    var e;
    (e = l.onCancel) === null || e === void 0 || e.call(l), W(!1);
  }, [A, g] = B(se), [I, q] = o.useState(!1), V = o.useRef(null), G = {};
  g.format && (G.format = g.format);
  const K = () => {
    V.current && clearTimeout(V.current);
  }, ue = (e) => {
    var t;
    e == null || e.preventDefault(), e == null || e.stopPropagation(), Ve(g.text || String(s) || "", G), q(!0), K(), V.current = setTimeout(() => {
      q(!1);
    }, 3e3), (t = g.onCopy) === null || t === void 0 || t.call(g, e);
  };
  o.useEffect(() => K, []);
  const [Q, me] = o.useState(!1), [X, ve] = o.useState(!1), [ye, Ee] = o.useState(!1), [Y, be] = o.useState(!1), [Z, ge] = o.useState(!1), [xe, Ce] = o.useState(!0), [E, r] = B(P, {
    expandable: !1
  }), m = E && !ye, {
    rows: x = 1
  } = r, L = o.useMemo(() => (
    // Disable ellipsis
    !m || // Provide suffix
    r.suffix !== void 0 || r.onEllipsis || // Can't use css ellipsis since we need to provide the place for button
    r.expandable || M || A
  ), [m, r, M, A]);
  Fe(() => {
    E && !L && (me(oe("webkitLineClamp")), ve(oe("textOverflow")));
  }, [L, E]);
  const v = o.useMemo(() => L ? !1 : x === 1 ? X : Q, [L, X, Q]), ee = m && (v ? Z : Y), Se = m && x === 1 && v, T = m && x > 1 && v, he = (e) => {
    var t;
    Ee(!0), (t = r.onExpand) === null || t === void 0 || t.call(r, e);
  }, [Oe, we] = o.useState(0), [ke, Ie] = o.useState(0), Le = (e, t) => {
    let {
      offsetWidth: c
    } = e;
    var d;
    we(c), Ie(parseInt((d = window.getComputedStyle) === null || d === void 0 ? void 0 : d.call(window, t).fontSize, 10) || 0);
  }, Te = (e) => {
    var t;
    be(e), Y !== e && ((t = r.onEllipsis) === null || t === void 0 || t.call(r, e));
  };
  o.useEffect(() => {
    const e = z.current;
    if (E && v && e) {
      const t = T ? e.offsetHeight < e.scrollHeight : e.offsetWidth < e.scrollWidth;
      Z !== t && ge(t);
    }
  }, [E, v, s, T, xe]), o.useEffect(() => {
    const e = z.current;
    if (typeof IntersectionObserver > "u" || !e || !v || !m)
      return;
    const t = new IntersectionObserver(() => {
      Ce(!!e.offsetParent);
    });
    return t.observe(e), () => {
      t.disconnect();
    };
  }, [v, m]);
  let b = {};
  r.tooltip === !0 ? b = {
    title: (f = l.text) !== null && f !== void 0 ? f : s
  } : /* @__PURE__ */ o.isValidElement(r.tooltip) ? b = {
    title: r.tooltip
  } : typeof r.tooltip == "object" ? b = Object.assign({
    title: (a = l.text) !== null && a !== void 0 ? a : s
  }, r.tooltip) : b = {
    title: r.tooltip
  };
  const _ = o.useMemo(() => {
    const e = (t) => ["string", "number"].includes(typeof t);
    if (!(!E || v)) {
      if (e(l.text))
        return l.text;
      if (e(s))
        return s;
      if (e(k))
        return k;
      if (e(b.title))
        return b.title;
    }
  }, [E, v, k, b.title, ee]);
  if (j)
    return /* @__PURE__ */ o.createElement(Ge, {
      value: (p = l.text) !== null && p !== void 0 ? p : typeof s == "string" ? s : "",
      onSave: de,
      onCancel: fe,
      onEnd: l.onEnd,
      prefixCls: u,
      className: h,
      style: O,
      direction: F,
      component: D,
      maxLength: l.maxLength,
      autoSize: l.autoSize,
      enterIcon: l.enterIcon
    });
  const _e = () => {
    const {
      expandable: e,
      symbol: t
    } = r;
    if (!e)
      return null;
    let c;
    return t ? c = t : c = n == null ? void 0 : n.expand, /* @__PURE__ */ o.createElement("a", {
      key: "expand",
      className: `${u}-expand`,
      onClick: he,
      "aria-label": n == null ? void 0 : n.expand
    }, c);
  }, Ne = () => {
    if (!M)
      return;
    const {
      icon: e,
      tooltip: t
    } = l, c = De(t)[0] || (n == null ? void 0 : n.edit), d = typeof c == "string" ? c : "";
    return H.includes("icon") ? /* @__PURE__ */ o.createElement(ne, {
      key: "edit",
      title: t === !1 ? "" : c
    }, /* @__PURE__ */ o.createElement(ie, {
      ref: J,
      className: `${u}-edit`,
      onClick: U,
      "aria-label": d
    }, e || /* @__PURE__ */ o.createElement(Ae, {
      role: "button"
    }))) : null;
  }, Re = () => {
    if (!A)
      return;
    const {
      tooltips: e,
      icon: t
    } = g, c = le(e), d = le(t), N = I ? R(c[1], n == null ? void 0 : n.copied) : R(c[0], n == null ? void 0 : n.copy), ze = I ? n == null ? void 0 : n.copied : n == null ? void 0 : n.copy, Me = typeof N == "string" ? N : ze;
    return /* @__PURE__ */ o.createElement(ne, {
      key: "copy",
      title: N
    }, /* @__PURE__ */ o.createElement(ie, {
      className: te(`${u}-copy`, I && `${u}-copy-success`),
      onClick: ue,
      "aria-label": Me
    }, I ? R(d[1], /* @__PURE__ */ o.createElement(je, null), !0) : R(d[0], /* @__PURE__ */ o.createElement(We, null), !0)));
  }, Pe = (e) => [e && _e(), Ne(), Re()], $e = (e) => [e && /* @__PURE__ */ o.createElement("span", {
    "aria-hidden": !0,
    key: "ellipsis"
  }, ot), r.suffix, Pe(e)];
  return /* @__PURE__ */ o.createElement(Be, {
    onResize: Le,
    disabled: !m || v
  }, (e) => /* @__PURE__ */ o.createElement(Ye, {
    tooltipProps: b,
    enabledEllipsis: m,
    isEllipsis: ee
  }, /* @__PURE__ */ o.createElement(Ke, Object.assign({
    className: te({
      [`${u}-${w}`]: w,
      [`${u}-disabled`]: C,
      [`${u}-ellipsis`]: E,
      [`${u}-single-line`]: m && x === 1,
      [`${u}-ellipsis-single-line`]: Se,
      [`${u}-ellipsis-multiple-line`]: T
    }, h),
    prefixCls: S,
    style: Object.assign(Object.assign({}, O), {
      WebkitLineClamp: T ? x : void 0
    }),
    component: D,
    ref: Ue(e, z, y),
    direction: F,
    onClick: H.includes("text") ? U : void 0,
    "aria-label": _ == null ? void 0 : _.toString(),
    title: k
  }, ce), /* @__PURE__ */ o.createElement(Xe, {
    enabledMeasure: m && !v,
    text: s,
    rows: x,
    width: Oe,
    fontSize: ke,
    onEllipsis: Te
  }, (t, c) => {
    let d = t;
    return t.length && c && _ && (d = /* @__PURE__ */ o.createElement("span", {
      key: "show-content",
      "aria-hidden": !0
    }, d)), tt(i, /* @__PURE__ */ o.createElement(o.Fragment, null, d, $e(c)));
  }))));
}), It = it;
export {
  It as default
};
