const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index = require("../../../filter/components/QuickFilter/index.js");
const require_useRecordBoardContext = require("../../hooks/useRecordBoardContext.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
//#region src/components/pisellRecordBoard/shellFrame/ToolBarQuickFilter/index.tsx
/** 筛选在 searchParams 中的字段名，与 ToolBar 一致 */
const FILTER_PARAMS_FIELD = "filter";
/**
* RecordBoard 工具栏左侧内联快速筛选：将 quickFilter 直接展示在 ToolBar 左侧，不放入 Filter 弹层。
* 与 searchParams.filter 联动，变更写入 searchParams.filter.values 并触发 onSearch。
* 启用时建议 ToolBar 对 PisellFilter 传 hiddenQuickFilter: true，仅保留高级筛选在弹层内。
*/
const ToolBarQuickFilter = ({ filterList = [], formFiltersPrefix = "", size = "large", phoneLayout }) => {
	var _filterValue$values;
	const { searchParams, onSearch } = require_useRecordBoardContext.useRecordBoardContext();
	const [form] = antd.Form.useForm();
	const filterValue = searchParams === null || searchParams === void 0 ? void 0 : searchParams[FILTER_PARAMS_FIELD];
	const currentValues = (_filterValue$values = filterValue === null || filterValue === void 0 ? void 0 : filterValue.values) !== null && _filterValue$values !== void 0 ? _filterValue$values : {};
	(0, react.useEffect)(() => {
		const next = typeof currentValues === "object" && currentValues !== null ? currentValues : {};
		const byNames = filterList.reduce((acc, item) => {
			var _other, _item$name, _next$String2;
			const composite = item === null || item === void 0 || (_other = item.other) === null || _other === void 0 ? void 0 : _other.compositeFilterFieldNames;
			if (Array.isArray(composite) && composite.length > 0) {
				for (const field of composite) {
					var _next$String;
					acc[String(field)] = (_next$String = next[String(field)]) !== null && _next$String !== void 0 ? _next$String : void 0;
				}
				return acc;
			}
			const name = (_item$name = item.name) !== null && _item$name !== void 0 ? _item$name : item.key;
			if (name != null) acc[String(name)] = (_next$String2 = next[String(name)]) !== null && _next$String2 !== void 0 ? _next$String2 : void 0;
			return acc;
		}, {});
		form.setFieldsValue(byNames);
	}, [
		currentValues,
		form,
		filterList
	]);
	const handleValuesChange = (0, react.useCallback)((_, allValues) => {
		if (typeof allValues !== "object" || allValues === null) return;
		const nextFilter = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, filterValue), {}, { values: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, currentValues), allValues) });
		onSearch(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, searchParams), {}, { [FILTER_PARAMS_FIELD]: nextFilter }));
	}, [
		searchParams,
		filterValue,
		currentValues,
		onSearch
	]);
	if (!Array.isArray(filterList) || filterList.length === 0) return null;
	return /* @__PURE__ */ react.default.createElement(antd.Form, {
		form,
		layout: "inline",
		size,
		onValuesChange: handleValuesChange,
		style: { marginRight: 0 },
		className: "record-board-toolbar-quick-filter-form"
	}, /* @__PURE__ */ react.default.createElement(require_index.default, {
		value: { quickFilter: filterList },
		formFiltersPrefix,
		phoneLayout,
		phoneQuickFilterSlot: Boolean(phoneLayout)
	}));
};
ToolBarQuickFilter.displayName = "RecordBoard.ToolBarQuickFilter";
//#endregion
exports.default = ToolBarQuickFilter;
