require("../../../_virtual/_rolldown/runtime.js");
const require_utils = require("../Table/utils.js");
let react = require("react");
//#region src/components/table/hooks/useTriggerValuesChange.ts
/**
* 判断是否触发值变化
* @param params 参数对象，包含 filter、columnSetting、dataSourceGroup、sort
* @returns 返回一个函数，用于判断是否触发值变化
*/
const useTriggerValuesChange = (params) => {
	const { filter, columnSetting, dataSourceGroup, sort, currentViewMode } = params;
	const { list, show } = filter || {};
	const { list: sortList, show: sortShow } = sort || {};
	const lastIsRemoteSort = (0, react.useRef)(false);
	return (0, react.useCallback)((changedValues, values) => {
		const keys = require_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 || sortList === void 0 ? void 0 : sortList.length)) {
				var _value$split;
				const value = changedValues[changedKey];
				const sortField = (value === null || value === void 0 || (_value$split = value.split) === null || _value$split === void 0 || (_value$split = _value$split.call(value, ":")) === null || _value$split === void 0 ? void 0 : _value$split[0]) || "";
				const result = sortList.filter((item) => !item.localFilter).map((item) => {
					var _item$name;
					return (_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.toString();
				}).includes(sortField);
				if (sortField === "" && lastIsRemoteSort.current) {
					lastIsRemoteSort.current = false;
					return true;
				}
				if (sortField !== "") lastIsRemoteSort.current = result;
				return result;
			}
		}
		/**
		* 过滤器变化时，如果过滤器有远程过滤，则触发值变化
		*/
		if (changedKey === "filters") {
			var _Object$keys;
			const filterKey = ((_Object$keys = Object.keys(changedValues.filters)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0]) || "";
			if (show && (list === null || list === void 0 ? void 0 : list.length)) return list.filter((item) => !item.localFilter).map((item) => {
				var _item$name2;
				return (_item$name2 = item.name) === null || _item$name2 === void 0 ? void 0 : _item$name2.toString();
			}).includes(filterKey);
		}
		/**
		* 表格配置变化时，如果表格配置有远程处理，则触发值变化
		*/
		if (keys.includes(changedKey)) return true;
	}, [
		filter,
		columnSetting,
		dataSourceGroup,
		sort
	]);
};
//#endregion
exports.default = useTriggerValuesChange;
