var L = Object.defineProperty;
var N = (e, t, i) => t in e ? L(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
var p = (e, t, i) => (N(e, typeof t != "symbol" ? t + "" : t, i), i);
import { b9 as F, P as _, bh as j, V as u, jN as R, c1 as m, ea as S, a as I, M as A, dV as D, dX as z } from "./684d2f28.js";
import P, { useRef as H, useState as V, useMemo as W, useEffect as T, useContext as U, useCallback as E } from "react";
import { TableCellContext as q } from "./b1144c16.js";
const Y = F.div`
  ${(e) => !e.$textOverflow && `
    div {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      word-break: keep-all;
    }
  `}
`, X = F.div`
  position: absolute;
  height: ${(e) => e.$adjustHeight ? `${e.$adjustHeight}px` : "max-content"};
  width: ${(e) => e.$adjustWidth ? `${e.$adjustWidth}px` : "max-content"};
  visibility: ${(e) => e.$visible ? "visible" : "hidden"};
  min-width: ${(e) => e.$minWidth ? `${e.$minWidth}px` : "unset"};
  max-height: 150px;
  max-width: 300px;
  overflow: auto;
  background: inherit;
  z-index: 3;
  padding: ${(e) => e.$padding};
  top: ${(e) => `${e.$adjustTop || 0}px`};
  left: ${(e) => `${e.$adjustLeft || 0}px`};

  &::-webkit-scrollbar {
    width: 16px;
  }

  &::-webkit-scrollbar-thumb {
    border: 5px solid transparent;
    background-clip: content-box;
    border-radius: 9999px;
    background-color: rgba(139, 143, 163, 0.2);
    min-height: 30px;
  }

  &::-webkit-scrollbar-thumb:hover {
    background-color: rgba(139, 143, 163, 0.5);
  }
`;
function k(e) {
  for (let t = 0; t < e.length; t++) {
    const i = e[t];
    return i.clientHeight < i.scrollHeight || i.clientWidth < i.scrollWidth ? !0 : k(i.children);
  }
  return !1;
}
function G(e) {
  var w;
  const t = H(null), i = H(null), [o, a] = V(!1), [r, d] = V(!1), [c, h] = V({
    done: !1
  }), [g, f] = V(), C = W(() => () => f(setTimeout(() => {
    a(!0);
  }, 300)), []);
  return T(() => {
    const n = t.current;
    if (!o || !n)
      return;
    n.clientHeight < n.scrollHeight || n.clientWidth < n.scrollWidth || k(n.children) ? !r && d(!0) : r && d(!1);
  }, [o]), T(() => {
    var B;
    const n = t.current, l = i.current;
    if (!o || !r) {
      n != null && n.parentElement && (n.parentElement.style.zIndex = ""), h({
        done: !1
      });
      return;
    }
    const s = (B = t.current) == null ? void 0 : B.closest(".ant-table-content");
    if (!l || !s || !n)
      return;
    n.parentElement && (n.parentElement.style.zIndex = "999");
    const b = Math.min(l.getBoundingClientRect().width, s.getBoundingClientRect().width), x = Math.min(l.getBoundingClientRect().height, s.getBoundingClientRect().height);
    let v;
    const y = s.getBoundingClientRect().x - l.getBoundingClientRect().x, $ = s.getBoundingClientRect().x + s.offsetWidth - (l.getBoundingClientRect().x + b);
    y > 0 ? v = y : $ < 0 && (v = $);
    const O = s.getBoundingClientRect().y + s.offsetHeight - (l.getBoundingClientRect().y + x);
    h({
      left: v,
      top: O < 0 ? O : void 0,
      height: x,
      width: b,
      done: !0
    });
  }, [o, r]), /* @__PURE__ */ _(j, {
    children: [/* @__PURE__ */ u(Y, {
      ref: t,
      $textOverflow: e.textOverflow,
      onMouseEnter: () => {
        C();
      },
      onMouseLeave: () => {
        clearTimeout(g), a(!1);
      },
      children: e.children
    }), o && r && t.current && !e.textOverflow && /* @__PURE__ */ u(X, {
      ref: i,
      $visible: c.done,
      $minWidth: (w = t.current.offsetParent) == null ? void 0 : w.clientWidth,
      $adjustWidth: c.width,
      $adjustHeight: c.height,
      $adjustLeft: c.left,
      $adjustTop: c.top,
      $padding: `${t.current.offsetTop}px ${t.current.offsetLeft}px`,
      onMouseEnter: () => {
        a(!0);
      },
      onMouseLeave: () => a(!1),
      children: e.children
    })]
  });
}
const J = P.createContext([]), K = P.createContext([]), Q = F.div`
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 2;

  width: 0px;
  height: 0px;
  border: 4.5px solid transparent;
  border-radius: 2px;
  border-top-color: ${R[1].color};
  border-right-color: ${R[1].color};
`, Z = F.div`
  position: absolute;
  border: 1.5px solid #315efb;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
`;
function ee(e) {
  const {
    dispatch: t,
    normalView: i,
    editViewFn: o,
    changeValue: a,
    baseValue: r,
    candidateTags: d,
    candidateStatus: c,
    onTableEvent: h
  } = e, g = m.isNil(a) ? "normal" : "toSave", f = o ? e.editable : !1, {
    isEditing: C,
    setIsEditing: w
  } = U(q), n = a ?? r, [l, s] = V(n);
  T(() => {
    s(n);
  }, [n]);
  const b = E(($) => {
    s($);
  }, [s]), x = E(() => {
    w(!1), t(S("changeValue", m.isNil(l) || m.isEqual(l, r) ? null : l, !1)), m.isEqual(l, n) || h == null || h("columnEdited");
  }, [t, r, l]), v = W(() => (o == null ? void 0 : o({
    value: n,
    onChange: b,
    onChangeEnd: x
  })) ?? /* @__PURE__ */ u(j, {}), [o, n, b, x]), y = E(() => {
    f && w(!0);
  }, [f]);
  return C ? /* @__PURE__ */ _(j, {
    children: [/* @__PURE__ */ u(Z, {}), /* @__PURE__ */ u(J.Provider, {
      value: d ?? [],
      children: /* @__PURE__ */ u(K.Provider, {
        value: c ?? [],
        children: v
      })
    })]
  }) : /* @__PURE__ */ _(G, {
    textOverflow: e.textOverflow,
    children: [g === "toSave" && !C && /* @__PURE__ */ u(Q, {}), /* @__PURE__ */ u("div", {
      onDoubleClick: y,
      children: i
    })]
  });
}
const M = "__COLUMN_DISPLAY_VALUE_FN";
class te {
  constructor(t, i, o, a) {
    p(this, "childrenMap");
    p(this, "propertyViewFn");
    p(this, "stylePropertyViewFn");
    p(this, "editViewFn");
    this.viewFn = i, this.displayValueFn = o, this.baseValueFn = a, this.childrenMap = {
      ...t,
      changeValue: I(null)
    };
  }
  setEditViewFn(t) {
    return this.editViewFn = t, this;
  }
  setPropertyViewFn(t) {
    return this.propertyViewFn = t, this;
  }
  setStylePropertyViewFn(t) {
    return this.stylePropertyViewFn = t, this;
  }
  build() {
    if (!this.propertyViewFn)
      throw new Error("need property view fn");
    const t = (r, d) => (c) => {
      var f;
      const h = (f = this.baseValueFn) == null ? void 0 : f.call(this, r, d), g = this.viewFn(r, d);
      return /* @__PURE__ */ u(ee, {
        ...c,
        normalView: g,
        dispatch: d,
        baseValue: h,
        changeValue: r.changeValue,
        editViewFn: this.editViewFn
      });
    }, i = new A(this.childrenMap, t).setPropertyViewFn(this.propertyViewFn).build(), o = this.displayValueFn, a = this.editViewFn;
    return class extends i {
      constructor() {
        super(...arguments);
        // table cell data
        p(this, "displayValue", null);
      }
      extraNode() {
        return {
          node: {
            [M]: D(z(this.childrenNode()), () => o)
          },
          updateNodeFields: (d) => {
            const c = d[M];
            return {
              displayValue: c(d)
            };
          }
        };
      }
      /**
       * Get the data actually displayed by the table cell
       */
      getDisplayValue() {
        return this.displayValue;
      }
      static canBeEditable() {
        return !m.isNil(a);
      }
    };
  }
}
const le = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  ColumnTypeCompBuilder: te,
  __COLUMN_DISPLAY_VALUE_FN: M
}, Symbol.toStringTag, { value: "Module" }));
export {
  te as C,
  K as S,
  J as T,
  M as _,
  le as c
};
