import { withInstall as B } from "@das-fed/upf-utils/with-install/index";
import { defineComponent as D, ref as s, computed as M, onMounted as L, nextTick as I, openBlock as O, createBlock as R, Teleport as T, createElementVNode as H, normalizeStyle as W, toDisplayString as $ } from "vue";
const j = /* @__PURE__ */ D({
  __name: "index",
  props: {
    getEl: {},
    errorLabel: { default: "" },
    errorModelZIndex: { default: 2e3 },
    errorWidth: { default: void 0 }
  },
  setup(x) {
    const r = x, k = s(null), l = s(), i = s({
      x: 0,
      y: 0
    }), v = M(() => ({
      "box-sizing": "border-box",
      "font-size": "12px",
      // 错误浮层直接消费 upf 根变量，确保 Teleport 到 body 后仍随主题同步。
      "background-color": "var(--upf-message-error-bg, var(--upf-bg-primary))",
      "box-shadow": "var(--upf-box-shadow-elevated, 0px 4px 12px rgba(38, 38, 38, 0.12))",
      "border-radius": "var(--upf-border-radius, 4px)",
      padding: "2px 8px",
      "z-index": r.errorModelZIndex
    })), w = M(() => {
      const n = l.value ?? "0";
      return {
        ...v.value,
        width: n + (/px$/.test(n) ? "" : "px"),
        position: "fixed",
        visibility: "visible",
        top: i.value.y + "px",
        left: i.value.x + "px"
      };
    }), c = s({
      // display: 'block',
      color: "var(--upf-message-error-text, var(--upf-color-error))",
      "white-space": "break-spaces"
    }), E = () => {
      const n = (d = 0) => {
        const t = document.createElement("div");
        for (let [p, h] of Object.entries({
          ...v.value,
          ...c.value,
          width: d + "px"
        }))
          t.style[p] = h;
        const o = document.createElement("span");
        for (let [p, h] of Object.entries(c.value))
          o.style[p] = h;
        o.textContent = r.errorLabel, t.appendChild(o), document.body.appendChild(t);
        const y = t.offsetHeight, z = o.offsetWidth;
        return document.body.removeChild(t), { height: y, textWidth: z };
      }, g = () => {
        const d = document.documentElement.clientHeight, o = document.documentElement.scrollHeight - d;
        return d - o;
      }, e = r.getEl(), a = (e == null ? void 0 : e.clientWidth) ?? 0, m = n(a), f = m.textWidth;
      r.errorWidth ? l.value = r.errorWidth : f > a ? l.value = f + 2 + 8 + "px" : l.value = a + "px";
      const { left: C = 0, bottom: u = 0, height: S = 0 } = (e == null ? void 0 : e.getBoundingClientRect()) ?? {}, _ = g(), b = m.height;
      i.value.y = Math.ceil(u + b) >= _ ? u - S - b : u, i.value.x = C;
    };
    return L(async () => {
      await I(), E();
    }), (n, g) => (O(), R(T, { to: "body" }, [
      H(
        "div",
        {
          ref_key: "$errorModel",
          ref: k,
          style: W(w.value)
        },
        [
          H(
            "span",
            {
              style: W(c.value)
            },
            $(x.errorLabel),
            5
            /* TEXT, STYLE */
          )
        ],
        4
        /* STYLE */
      )
    ]));
  }
}), V = B(j);
export {
  V as DasErrorOverlayModel
};
