import { getText } from "../../../../locales/index.js";
import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import FilterItem from "../FilterItem/index.js";
import MultipleContainersSortList from "../../../MultipleContainersSortList/index.js";
import React, { useCallback, useMemo } from "react";
import { Tooltip } from "antd";
import DotsSix from "@pisell/icon/es/DotsSix";
import HelpCircle from "@pisell/icon/es/HelpCircle";
import "./index.less";
//#region src/components/filter/components/Dropdown/index.tsx
const DragItem = React.forwardRef((props, ref) => {
	const { attributes, listeners, setActivatorNodeRef, style } = props;
	return /* @__PURE__ */ React.createElement("div", _objectSpread2(_objectSpread2({ ref }, attributes), {}, {
		style,
		className: "filter-dropdown-drag-item"
	}), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(DotsSix, _objectSpread2(_objectSpread2({ ref: setActivatorNodeRef }, listeners), {}, {
		style: _objectSpread2(_objectSpread2({}, listeners.style || {}), {}, { touchAction: "none" }),
		className: "dots-six-icon"
	}))), /* @__PURE__ */ React.createElement("div", { className: "filter-dropdown-drag-item-right" }, props.children));
});
const Dropdown$1 = (props) => {
	const { quickFilter, hiddenQuickFilter, hiddenOtherFilter, otherFilter, onChange, quickFilterMaxLength, formFiltersPrefix, onOpen, onClose, renderItem } = props;
	const list = 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: getText("table-action-filter-quick-filter"),
		otherFilter: getText("table-action-filter-other-filter")
	};
	const tooltipMap = {
		quickFilter: getText("table-action-filter-quick-filter-tip"),
		otherFilter: getText("table-action-filter-other-filter-tip")
	};
	const getTooltipTitle = useCallback((id) => {
		const fn = tooltipMap[id];
		return typeof fn === "function" ? fn(quickFilterMaxLength) : fn;
	}, [quickFilterMaxLength]);
	const renderContainer = useCallback(({ children, ref, id }) => {
		return /* @__PURE__ */ React.createElement("div", { className: "filter-dropdown-container-wrap" }, /* @__PURE__ */ React.createElement("div", { className: "filter-dropdown-container-title-wrap" }, /* @__PURE__ */ React.createElement("span", { className: "filter-dropdown-container-title" }, titleMap[id]), /* @__PURE__ */ React.createElement(Tooltip, { title: getTooltipTitle(id) }, /* @__PURE__ */ React.createElement(HelpCircle, { className: "filter-dropdown-container-icon-help" }))), /* @__PURE__ */ React.createElement("div", {
			ref,
			className: "filter-dropdown-container-filter-wrap"
		}, children));
	}, [quickFilterMaxLength, getTooltipTitle]);
	return /* @__PURE__ */ React.createElement("div", { className: "filter-dropdown-wrap" }, /* @__PURE__ */ React.createElement("div", { className: "filter-dropdown-wrap-content" }, /* @__PURE__ */ React.createElement(MultipleContainersSortList, {
		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.createElement(DragItem, _objectSpread2(_objectSpread2({}, props), {}, {
			index,
			attributes,
			setActivatorNodeRef,
			listeners,
			style
		}), renderItem ? renderItem(item, {
			onOpen,
			onClose
		}) : /* @__PURE__ */ React.createElement(FilterItem, {
			key: name.join("-"),
			name,
			label: item.label,
			type: item.type,
			other: _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: _objectSpread2(_objectSpread2({}, ((_item$other3 = item.other) === null || _item$other3 === void 0 ? void 0 : _item$other3.style) || {}), {}, { width: "100%" })
			}),
			props: item.props
		}));
	})));
};
//#endregion
export { Dropdown$1 as default };
