import { defineComponent as C, ref as P, createVNode as n, mergeProps as H } from "vue";
import { isFunction as w, isEmpty as f, omitBy as y, isUndefined as A, omit as I } from "lodash-unified";
import "../../../ag-grid/index.mjs";
import { ApModal as M } from "../../../ap-modal/index.mjs";
import { genRequest as x } from "../utils.mjs";
import "../wrapper/index.vue.mjs";
import { useAgGridInstance as G } from "./use-ag-grid-instance.mjs";
import _ from "../wrapper/index.vue2.mjs";
import q from "../../../ag-grid/index.vue.mjs";
function z(o) {
  let a = null, l = null;
  const [r, g] = G(), s = x(o.api, o.getRowKey), d = (t) => {
    const {
      title: e,
      width: i,
      modalProps: v,
      ...u
    } = w(t) ? t(o) : t;
    f(u) || l?.(u);
    const m = y({
      title: e,
      width: i,
      modalProps: v
    }, A);
    f(m) || a?.update(m);
  }, c = /* @__PURE__ */ C({
    name: "AgGridModalPreviewContent",
    props: {
      modalConfig: {
        type: Object,
        required: !0
      }
    },
    setup(t) {
      const e = P(t.modalConfig);
      return l = (i) => {
        e.value = {
          ...e.value,
          ...i
        };
      }, () => n(g, null, {
        default: () => [n(_, {
          height: e.value.height,
          rowHeight: e.value.rowHeight,
          minHeight: e.value.minHeight,
          maxHeight: e.value.maxHeight
        }, {
          default: () => [e.value.renderHeader?.(I(r, "setInstance"), {
            updateProps: d
          }), n(q, H({
            ref: r.setInstance,
            searchForm: {
              sortable: !1,
              resize: {
                target: "form"
              }
            },
            rowKey: e.value.getRowKey,
            request: s.request,
            style: {
              padding: "0px"
            },
            rowHeight: e.value.rowHeight,
            columns: e.value.columns,
            autoHeight: e.value.height === "auto",
            onModelUpdated: r.onAgGridUpdate
          }, o.gridProps), e.value.gridSlots)]
        })]
      });
    }
  });
  function h() {
    a = M.createModal({
      title: o.title,
      width: o.width,
      destroyOnClose: !0,
      maskClosable: !1,
      footer: null,
      afterOpenChange(t) {
        t === !1 && (r.setInstance(void 0), a = null);
      },
      content: n(c, {
        modalConfig: o
      }, null),
      ...o.modalProps || {}
    });
  }
  function p(t) {
    s.setExtraParams(t?.extraParams), h();
  }
  return {
    open: p,
    refresh: r.refresh,
    getAgGridInstance: r.getInstance,
    updateProps: d
  };
}
export {
  z as useAgGridModal
};
