import { jsxs as D, jsx as w } from "react/jsx-runtime";
import { useLatest as O, useDebounceFn as S } from "ahooks";
import { useState as s, useRef as x, useImperativeHandle as z, useEffect as b } from "react";
import { Box as C } from "@mui/material";
import { styled as W } from "../Theme/index.js";
import E from "./did-address.js";
import { getFontSize as L } from "../Util/index.js";
function J({
  ref: e = void 0,
  style: g = {},
  className: y = void 0,
  component: i = "span",
  size: o = 0,
  ...u
}) {
  const [p, R] = s(!1), F = O(p), [l, h] = s(null), [d, m] = s(null), [a, A] = s(!0), { run: v } = S(() => A(!1), {
    wait: 50
  }), n = x(null), t = x(null);
  return z(
    e,
    () => new Proxy(
      {},
      {
        get(c, r) {
          return t.current?.[r];
        }
      }
    )
  ), b(() => {
    const c = t.current?.offsetWidth || 0;
    let r = null, f = null;
    return h(c), m(n.current?.offsetWidth), r = new ResizeObserver(() => {
      !F.current && t.current?.offsetWidth !== c && (h(t.current?.offsetWidth), v());
    }), f = new ResizeObserver(() => {
      m(n.current?.offsetWidth);
    }), r.observe(t.current.getEl()), f.observe(n.current), v(), () => {
      r?.disconnect(), f?.disconnect();
    };
  }, []), b(() => {
    d && l && R(d < l);
  }, [d, l]), /* @__PURE__ */ D(
    $,
    {
      as: i,
      ref: n,
      style: g,
      className: y,
      size: o,
      ...i === "span" ? {} : {
        inline: u.inline
      },
      children: [
        /* @__PURE__ */ w(
          j,
          {
            style: {
              position: a ? "absolute" : "static",
              left: a ? "-99999px" : "auto"
            },
            ...u,
            size: o,
            component: i,
            inline: !0,
            compact: p,
            ref: t
          }
        ),
        a && /* @__PURE__ */ w("div", { style: { width: "100%", height: `${(o || 16) * 1.5}px` } })
      ]
    }
  );
}
const $ = W(C, { shouldForwardProp: (e) => e !== "size" })`
  display: block;
  width: 100%; /* flex & column & align-items: flex-start 时, 块级元素不会自动铺满容器 */
  font-size: ${({ size: e }) => L(e)};
  overflow: hidden;
  ${({ inline: e }) => e && `
    display: inline-block;
    width: 100%;
  `}
`, j = W(E)`
  && {
    max-width: none;
  }
  .did-address-text {
    /* 禁止文本 Ellipsis/截断, 以便测量真实的宽度 */
    white-space: nowrap;
    overflow: visible;
    text-overflow: unset;
  }
`;
export {
  J as default
};
