const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../../locales/index.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index$1 = require("../Dropdown/index.js");
const require_platform = require("../../../../utils/platform.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
let _pisell_icon_es_FilterLines = require("@pisell/icon/es/FilterLines");
_pisell_icon_es_FilterLines = require_runtime.__toESM(_pisell_icon_es_FilterLines);
//#region src/components/filter/components/FilterButton/index.tsx
/** 与 Quick Filter 同源：优先 utils，若 utils 返回 key（未命中）则用 materials RecordBoard 再回退 table-action */
function getFilterButtonLabel(buttonText) {
	if (buttonText != null && buttonText !== "") return buttonText;
	const key = "pisell2.recordBoard.toolbar.filter";
	const fromUtils = _pisell_utils.locales.getText(key);
	if (fromUtils && fromUtils !== key) return fromUtils;
	return require_index.getText(key) || require_index.getText("table-action-filter-button");
}
const Filter = ({ value, hiddenQuickFilter, hiddenOtherFilter, onChange, quickFilterMaxLength, formFiltersPrefix, renderItem, placement, size = "large", buttonClassName, buttonText }) => {
	const ref = (0, react.useRef)(null);
	const [open, setOpen] = (0, react.useState)(false);
	const [dateRangeOpen, setDateRangeOpen] = (0, react.useState)(false);
	const quickFilter = (0, react.useMemo)(() => {
		return (value === null || value === void 0 ? void 0 : value.quickFilter) || [];
	}, [value === null || value === void 0 ? void 0 : value.quickFilter]);
	const otherFilter = (0, react.useMemo)(() => {
		return (value === null || value === void 0 ? void 0 : value.otherFilter) || [];
	}, [value === null || value === void 0 ? void 0 : value.otherFilter]);
	const handleChange = (newVal) => {
		onChange === null || onChange === void 0 || onChange(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, value), newVal));
	};
	const content = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			hiddenQuickFilter,
			hiddenOtherFilter,
			quickFilter,
			otherFilter,
			onChange: handleChange,
			quickFilterMaxLength,
			formFiltersPrefix,
			onOpen: () => setDateRangeOpen(true),
			onClose: () => setDateRangeOpen(false),
			renderItem
		});
	}, [
		quickFilter,
		hiddenQuickFilter,
		hiddenOtherFilter,
		otherFilter,
		quickFilterMaxLength,
		formFiltersPrefix,
		renderItem
	]);
	const isMobileBool = require_platform.isMobile();
	return /* @__PURE__ */ react.default.createElement("div", { ref }, /* @__PURE__ */ react.default.createElement(antd.Popover, {
		content,
		arrow: false,
		getPopupContainer: () => ref.current,
		trigger: ["click"],
		open,
		onOpenChange: (visible) => {
			if (dateRangeOpen && !visible) return;
			setOpen(visible);
		},
		placement: placement !== null && placement !== void 0 ? placement : "bottom"
	}, /* @__PURE__ */ react.default.createElement(antd.Button, {
		className: buttonClassName,
		icon: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_FilterLines.default, null),
		size
	}, isMobileBool ? null : getFilterButtonLabel(buttonText))));
};
//#endregion
exports.default = Filter;
