import { isFunction as g, merge as A, cloneDeep as F } from "lodash-unified";
import { ref as V } from "vue";
import { useKeepAliveFlag as w } from "./useKeepAliveFlag.mjs";
function O(l) {
  const r = V(null), {
    isShowRowSelection: u = !0,
    clearSelectionOnRequest: d = !0,
    transformSearchFormValues: o,
    api: a,
    tableRefresh: s = !0,
    clearDataOnDeactivated: f = !0,
    ...m
  } = l || {};
  let n = null;
  const i = () => {
    r.value?.rowSelection?.clearAll();
  }, c = (e) => {
    r.value?.submitWith(e);
  }, p = () => {
    r.value?.reset();
  }, { isDeactivated: h } = w({
    afterActivated() {
      (g(s) ? s() : s) && c();
    },
    afterDeactivated: () => f && c()
  });
  return [A(
    {
      // scroll，tableLayout，columnResizable设置表格可拖动
      columnResizable: !0,
      request: a ? async (e) => {
        if (h())
          return {
            data: [],
            total: 0
          };
        n = e.sort;
        const t = o ? o(e) : e;
        if (!a) throw new Error("api is not defined");
        const { records: v, total: S } = await a(t);
        return d && i(), {
          data: v,
          total: S
        };
      } : void 0,
      rowSelection: u ? {
        fixed: "left",
        columnWidth: 38
      } : void 0,
      /** Jackie 推荐方法 */
      onVnodeBeforeMount(e) {
        r.value = e.component?.exposed;
      },
      // 新UI规范，需要都添加分割线
      card: !0
    },
    m
  ), {
    reload: c,
    reset: p,
    getSearchFormValues: (e = !0) => {
      const t = r.value?.getSearchFormValues(!!e) || {};
      return o ? o(t) : t;
    },
    getAgGridInstance: () => r.value,
    getSearchFormValuesAndSorted: (e = !0) => {
      const t = r.value?.getSearchFormValues(!!e) || {};
      return t.sort = n && F(n), o ? o(t) : t;
    },
    clearSelection: i
  }];
}
export {
  O as usePageListAgGrid
};
