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("../FilterItem/index.js");
const require_index$2 = require("../../../MultipleContainersSortList/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_icon_es_DotsSix = require("@pisell/icon/es/DotsSix");
_pisell_icon_es_DotsSix = require_runtime.__toESM(_pisell_icon_es_DotsSix);
let _pisell_icon_es_HelpCircle = require("@pisell/icon/es/HelpCircle");
_pisell_icon_es_HelpCircle = require_runtime.__toESM(_pisell_icon_es_HelpCircle);
require("./index.less");
//#region src/components/filter/components/Dropdown/index.tsx
const DragItem = react.default.forwardRef((props, ref) => {
	const { attributes, listeners, setActivatorNodeRef, style } = props;
	return /* @__PURE__ */ react.default.createElement("div", require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ ref }, attributes), {}, {
		style,
		className: "filter-dropdown-drag-item"
	}), /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_DotsSix.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ ref: setActivatorNodeRef }, listeners), {}, {
		style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, listeners.style || {}), {}, { touchAction: "none" }),
		className: "dots-six-icon"
	}))), /* @__PURE__ */ react.default.createElement("div", { className: "filter-dropdown-drag-item-right" }, props.children));
});
const Dropdown = (props) => {
	const { quickFilter, hiddenQuickFilter, hiddenOtherFilter, otherFilter, onChange, quickFilterMaxLength, formFiltersPrefix, onOpen, onClose, renderItem } = props;
	const list = (0, react.useMemo)(() => {
		const _list = {};
		if (!hiddenQuickFilter) _list.quickFilter = quickFilter || [];
		if (!hiddenOtherFilter) _list.otherFilter = otherFilter || [];
		return _list;
	}, [
		quickFilter,
		otherFilter,
		hiddenQuickFilter,
		hiddenOtherFilter
	]);
	const handleSortChange = (list) => {
		onChange === null || onChange === void 0 || onChange(list);
	};
	const titleMap = {
		quickFilter: require_index.getText("table-action-filter-quick-filter"),
		otherFilter: require_index.getText("table-action-filter-other-filter")
	};
	const tooltipMap = {
		quickFilter: require_index.getText("table-action-filter-quick-filter-tip"),
		otherFilter: require_index.getText("table-action-filter-other-filter-tip")
	};
	const getTooltipTitle = (0, react.useCallback)((id) => {
		const fn = tooltipMap[id];
		return typeof fn === "function" ? fn(quickFilterMaxLength) : fn;
	}, [quickFilterMaxLength]);
	const renderContainer = (0, react.useCallback)(({ children, ref, id }) => {
		return /* @__PURE__ */ react.default.createElement("div", { className: "filter-dropdown-container-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "filter-dropdown-container-title-wrap" }, /* @__PURE__ */ react.default.createElement("span", { className: "filter-dropdown-container-title" }, titleMap[id]), /* @__PURE__ */ react.default.createElement(antd.Tooltip, { title: getTooltipTitle(id) }, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_HelpCircle.default, { className: "filter-dropdown-container-icon-help" }))), /* @__PURE__ */ react.default.createElement("div", {
			ref,
			className: "filter-dropdown-container-filter-wrap"
		}, children));
	}, [quickFilterMaxLength, getTooltipTitle]);
	return /* @__PURE__ */ react.default.createElement("div", { className: "filter-dropdown-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "filter-dropdown-wrap-content" }, /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		list,
		rowKey: "name",
		renderContainer,
		onChange: handleSortChange,
		quickFilterMaxLength
	}, ({ item, index, style, props, attributes, setActivatorNodeRef, listeners }) => {
		var _item$name, _item$other3;
		const name = [formFiltersPrefix, (_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.toString()].filter(Boolean);
		return /* @__PURE__ */ react.default.createElement(DragItem, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
			index,
			attributes,
			setActivatorNodeRef,
			listeners,
			style
		}), renderItem ? renderItem(item, {
			onOpen,
			onClose
		}) : /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			key: name.join("-"),
			name,
			label: item.label,
			type: item.type,
			other: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item.other), {}, {
				onOpen: () => {
					var _item$other, _item$other$onOpen;
					(_item$other = item.other) === null || _item$other === void 0 || (_item$other$onOpen = _item$other.onOpen) === null || _item$other$onOpen === void 0 || _item$other$onOpen.call(_item$other);
					onOpen === null || onOpen === void 0 || onOpen();
				},
				onClose: () => {
					var _item$other2, _item$other2$onClose;
					(_item$other2 = item.other) === null || _item$other2 === void 0 || (_item$other2$onClose = _item$other2.onClose) === null || _item$other2$onClose === void 0 || _item$other2$onClose.call(_item$other2);
					onClose === null || onClose === void 0 || onClose();
				},
				style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, ((_item$other3 = item.other) === null || _item$other3 === void 0 ? void 0 : _item$other3.style) || {}), {}, { width: "100%" })
			}),
			props: item.props
		}));
	})));
};
//#endregion
exports.default = Dropdown;
