import { getText } from "../../../../locales/index.js";
import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { useRecordBoardContext } from "../../hooks/useRecordBoardContext.js";
import React, { useCallback } from "react";
import { locales } from "@pisell/utils";
import { Button } from "antd";
import { ReloadOutlined } from "@ant-design/icons";
import "./index.less";
//#region src/components/pisellRecordBoard/shellFrame/ToolBarReset/index.tsx
/** 与 Quick Filter 同源：优先 utils，若 utils 返回 key（未命中）则用 materials 再回退 */
function getResetButtonText() {
	const key = "pisell2.recordBoard.toolbar.reset";
	const u = locales.getText(key);
	return u && u !== key ? u : getText(key) || getText("record-board-toolbar-reset");
}
/** 筛选在 searchParams 中的字段名，与 ToolBar 一致 */
const FILTER_PARAMS_FIELD = "filter";
/** 排序在 searchParams 中的字段名，与 ToolBar 一致 */
const SORT_PARAMS_FIELD = "sort";
/**
* RecordBoard 工具栏重置按钮：清空筛选与排序并刷新表格。
* 点击后以空 filter.values、清空 sort 调用 onSearch，并调用 onReset（若提供）。
*/
const ToolBarReset = ({ size = "large", type = "default", children }) => {
	const defaultResetText = getResetButtonText();
	const { searchParams, onSearch, onReset, setFilterResetKey } = useRecordBoardContext();
	const handleReset = useCallback(() => {
		var _currentFilter$otherF;
		setFilterResetKey === null || setFilterResetKey === void 0 || setFilterResetKey((prev) => prev + 1);
		const currentFilter = searchParams === null || searchParams === void 0 ? void 0 : searchParams[FILTER_PARAMS_FIELD];
		onSearch(_objectSpread2(_objectSpread2({}, searchParams), {}, {
			[FILTER_PARAMS_FIELD]: _objectSpread2(_objectSpread2({}, currentFilter), {}, {
				quickFilter: [],
				otherFilter: (_currentFilter$otherF = currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.otherFilter) !== null && _currentFilter$otherF !== void 0 ? _currentFilter$otherF : [],
				values: {}
			}),
			[SORT_PARAMS_FIELD]: void 0
		}));
		onReset === null || onReset === void 0 || onReset();
	}, [
		searchParams,
		onSearch,
		onReset,
		setFilterResetKey
	]);
	return /* @__PURE__ */ React.createElement(Button, {
		className: "record-board-toolbar-reset",
		type,
		icon: /* @__PURE__ */ React.createElement(ReloadOutlined, null),
		onClick: handleReset,
		size
	}, children !== null && children !== void 0 ? children : defaultResetText);
};
ToolBarReset.displayName = "RecordBoard.ToolBarReset";
//#endregion
export { ToolBarReset as default };
