import { defineComponent as R, useTemplateRef as b, ref as S, shallowRef as P, onUnmounted as k, openBlock as z, createBlock as A, unref as r, normalizeProps as M, guardReactiveProps as N, withCtx as T, createElementVNode as $, normalizeStyle as B, normalizeClass as D, renderSlot as I } from "vue";
import { isNil as h } from "lodash-unified";
import { APConfigProvider as U } from "../../config-provider/index.mjs";
import q from "./style/index.mjs";
import { useGlobalConfig as E } from "../../config-provider/hooks/use-global-config.mjs";
import { globalConfigCached as u } from "../../config-provider/config-provider.mjs";
import { useNamespace as V } from "../../config-provider/hooks/use-namespace.mjs";
const Q = /* @__PURE__ */ R({
  __name: "index",
  props: {
    minHeight: { default: 150 },
    maxHeight: { default: "unset" },
    mode: { default: void 0 }
  },
  emits: ["heightChange"],
  setup(n, { emit: d }) {
    const g = E(), p = u.value.agGrid, a = n, H = d, l = b("wrapperContainer"), s = S(c(a.minHeight)), { b: C, m: w } = V("ag-grid-container"), x = q("ag-grid-container"), m = (e) => {
      const o = l.value?.clientHeight, t = l.value?.querySelector(
        ".ag-body.ag-layout-normal"
      )?.clientHeight;
      let i = 0;
      !o || !t ? i = 0 : i = o - t;
      const G = e + i, f = Math.max(G, a.minHeight);
      s.value = `${f}px`, H("heightChange", f);
    }, v = (e) => {
      if (!e) return;
      const o = e.getDisplayedRowCount();
      if (o > 0) {
        const t = e.getDisplayedRowAtIndex(o - 1);
        if (t && !h(t.rowTop) && !h(t.rowHeight)) {
          const i = t.rowTop + t.rowHeight;
          m(i);
        }
      } else
        m(Math.max(a.minHeight, 86));
    }, y = P({
      ...g.value,
      agGrid: {
        ...g.value?.agGrid,
        onModelUpdated: v
      }
    });
    k(() => {
      u.value.agGrid = p;
    });
    function c(e) {
      return typeof e == "number" && e ? `${e}px` : e.toString();
    }
    return (e, o) => (z(), A(r(U), M(N(y.value)), {
      default: T(() => [
        $("div", {
          ref_key: "wrapperContainer",
          ref: l,
          class: D([r(C)(), n.mode === "form-item" ? r(w)("form-item") : "", r(x)]),
          style: B({
            height: s.value,
            maxHeight: n.maxHeight && c(n.maxHeight)
          })
        }, [
          I(e.$slots, "default")
        ], 6)
      ]),
      _: 3
    }, 16));
  }
});
export {
  Q as default
};
