var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/table/hooks/useTransDataSource.ts
var useTransDataSource_exports = {};
__export(useTransDataSource_exports, {
  default: () => useTransDataSource_default
});
module.exports = __toCommonJS(useTransDataSource_exports);
var import_react = require("react");
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_utils2 = require("../Table/utils");
var defaultObj = {};
var useTransDataSource = (params) => {
  const {
    form,
    localPagination,
    dataSource: pDataSource,
    rowKey,
    filter
  } = params;
  const sort = import_antd.Form.useWatch("order_by", { form, preserve: true });
  const group = import_antd.Form.useWatch("group_by", { form, preserve: true });
  const filters = import_antd.Form.useWatch("filters", { form, preserve: true }) || defaultObj;
  const sortObj = (0, import_react.useMemo)(() => {
    if (!sort) {
      return void 0;
    }
    const [key, value, type] = sort.split(":");
    return {
      sortKey: key,
      sortValue: value,
      sortType: type
    };
  }, [sort]);
  const groupDetail = (0, import_react.useMemo)(() => {
    if ((0, import_utils.isArr)(group) && group.length) {
      return group;
    }
    return void 0;
  }, [group]);
  const filterLocalArr = (0, import_react.useMemo)(() => {
    if (!(filter == null ? void 0 : filter.show) || !(filter == null ? void 0 : filter.list)) {
      return [];
    }
    return filter == null ? void 0 : filter.list.filter((item) => item.localFilter);
  }, [(0, import_utils2.stringify)(filter)]);
  const dataSource = (0, import_react.useMemo)(() => {
    if (!localPagination) {
      return pDataSource;
    }
    let newDataSource = pDataSource;
    if (filterLocalArr.length) {
      newDataSource = (0, import_utils2.filterDataSource)(newDataSource, filters, filterLocalArr);
    }
    if (sortObj) {
      newDataSource = (0, import_utils2.sortDataSource)(newDataSource, sortObj);
    }
    if (groupDetail) {
      newDataSource = (0, import_utils2.groupDataSource)(newDataSource, groupDetail, rowKey);
    }
    return newDataSource;
  }, [
    pDataSource,
    localPagination,
    sortObj,
    groupDetail,
    filterLocalArr,
    filters
  ]);
  return dataSource;
};
var useTransDataSource_default = useTransDataSource;
