import { cloneDeep as A } from "lodash-unified";
import { ref as l, watch as d, defineComponent as G, provide as I, toRef as u, inject as H } from "vue";
const a = /* @__PURE__ */ Symbol("ag-grid-provider-key");
function K(r) {
  const o = l(), s = l(), c = l(0), w = (e) => {
    o.value = e;
  }, v = () => o.value, g = (e = "reset") => {
    o.value && e in o.value && o.value[e]();
  }, f = (e) => {
    o.value?.rowSelection.setSelectedRowKeys(e);
  }, R = () => A(o.value?.rowSelection.selectedRows.value), S = () => o.value?.rowSelection.clearAll(), p = (e) => o.value?.rowSelection.unSelectRows([e]), h = (e) => {
    if (!e) return;
    const n = e.getDisplayedRowCount();
    if (n > 0) {
      const t = e.getDisplayedRowAtIndex(n - 1);
      if (t && t.rowTop && t.rowHeight) {
        const y = t.rowTop + t.rowHeight;
        c.value = y;
      }
    }
  };
  d(o, (e) => {
    e && r?.onMounted?.();
  }), d(
    () => o.value?.rowSelection.selectedRows.value,
    (e) => {
      s.value = e, r?.onSelectedRows?.(e);
    }
  );
  const i = {
    setInstance: w,
    refresh: g,
    getInstance: v,
    setSelectedRowKeys: f,
    getSelectedRows: R,
    clearAllSelected: S,
    removeSelected: p,
    onAgGridUpdate: h
  }, m = G({
    setup(e, { slots: n }) {
      return I(a, {
        ...i,
        selectedRows: u(() => s.value),
        agGridBodyHeight: u(() => c.value)
      }), () => n.default?.();
    },
    unmounted() {
      c.value = 0;
    }
  });
  return [i, m];
}
function j() {
  return H(a);
}
export {
  K as useAgGridInstance,
  j as useAgGridModalInject
};
