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/useTriggerValuesChange.ts
var useTriggerValuesChange_exports = {};
__export(useTriggerValuesChange_exports, {
  default: () => useTriggerValuesChange_default
});
module.exports = __toCommonJS(useTriggerValuesChange_exports);
var import_react = require("react");
var import_utils = require("../Table/utils");
var useTriggerValuesChange = (params) => {
  const { filter, columnSetting, dataSourceGroup, sort, currentViewMode } = params;
  const { list, show } = filter || {};
  const { list: sortList, show: sortShow } = sort || {};
  const lastIsRemoteSort = (0, import_react.useRef)(false);
  const getIsTriggerValuesChange = (0, import_react.useCallback)(
    (changedValues, values) => {
      var _a, _b, _c;
      const keys = (0, import_utils.getSettingKeyArrByMode)({
        filter,
        columnSetting,
        dataSourceGroup,
        sort,
        mode: "remote",
        currentViewMode
      });
      const changedKey = Object.keys(changedValues)[0];
      if (changedKey === "pagination") {
        return true;
      }
      if (changedKey === "view_mode") {
        return false;
      }
      if (changedKey === "tabs") {
        return true;
      }
      if (changedKey === "order_by") {
        if (sortShow && (sortList == null ? void 0 : sortList.length)) {
          const value = changedValues[changedKey];
          const sortField = ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b[0]) || "";
          const remoteSortKeys = sortList.filter((item) => !item.localFilter).map((item) => {
            var _a2;
            return (_a2 = item.name) == null ? void 0 : _a2.toString();
          });
          const result = remoteSortKeys.includes(sortField);
          if (sortField === "" && lastIsRemoteSort.current) {
            lastIsRemoteSort.current = false;
            return true;
          }
          if (sortField !== "") {
            lastIsRemoteSort.current = result;
          }
          return result;
        }
      }
      if (changedKey === "filters") {
        const filterKey = ((_c = Object.keys(changedValues.filters)) == null ? void 0 : _c[0]) || "";
        if (show && (list == null ? void 0 : list.length)) {
          const remoteFilterKeys = list.filter((item) => !item.localFilter).map((item) => {
            var _a2;
            return (_a2 = item.name) == null ? void 0 : _a2.toString();
          });
          return remoteFilterKeys.includes(filterKey);
        }
      }
      if (keys.includes(changedKey)) {
        return true;
      }
    },
    [filter, columnSetting, dataSourceGroup, sort]
  );
  return getIsTriggerValuesChange;
};
var useTriggerValuesChange_default = useTriggerValuesChange;
