import { getText } from "../../../locales/index.js";
import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import React, { useEffect, useMemo, useState } from "react";
import { Button, Checkbox, Menu, Space } from "antd";
import FilterFunnel01 from "@pisell/icon/es/FilterFunnel01";
import FilterFunnel01Fill from "@pisell/icon/es/FilterFunnel01Fill";
import "./index.less";
//#region src/components/table/TableFilter/selectFilter.tsx
const FilterDropdown = (props) => {
	const { setSelectedKeys, selectedKeys, confirm, clearFilters, filters } = props;
	const [value, setValue] = useState((selectedKeys === null || selectedKeys === void 0 ? void 0 : selectedKeys[0]) || []);
	useEffect(() => {
		setValue((selectedKeys === null || selectedKeys === void 0 ? void 0 : selectedKeys[0]) || []);
	}, [selectedKeys === null || selectedKeys === void 0 ? void 0 : selectedKeys[0]]);
	const items = useMemo(() => {
		return filters.map((item) => ({
			label: /* @__PURE__ */ React.createElement("span", { onClick: (e) => {
				e.preventDefault();
			} }, /* @__PURE__ */ React.createElement(Checkbox, { checked: value.includes(item.value) }, item.text)),
			key: item.value
		}));
	}, [filters, value]);
	const handleClick = ({ key }) => {
		setValue((v) => {
			if (v.includes(key)) return v.filter((item) => item !== key);
			return [...v, key];
		});
	};
	useEffect(() => {
		setSelectedKeys((value === null || value === void 0 ? void 0 : value.length) ? [value] : []);
	}, [value]);
	return /* @__PURE__ */ React.createElement("div", {
		onKeyDown: (e) => e.stopPropagation(),
		className: "pisell-table-filter-dropdown"
	}, /* @__PURE__ */ React.createElement("div", {
		className: "pisell-table-filter-dropdown-top",
		style: { padding: 0 }
	}, /* @__PURE__ */ React.createElement(Menu, {
		onClick: handleClick,
		items,
		selectedKeys: [],
		style: { width: 272 }
	})), /* @__PURE__ */ React.createElement(Space, {
		className: "pisell-table-filter-dropdown-bottom",
		styles: { item: { flex: 1 } }
	}, /* @__PURE__ */ React.createElement(Button, {
		onClick: () => {
			clearFilters && clearFilters();
			confirm();
		},
		block: true,
		style: { flex: 1 }
	}, getText("table-filter-clear")), /* @__PURE__ */ React.createElement(Button, {
		type: "primary",
		onClick: () => confirm(),
		block: true,
		style: { flex: 1 }
	}, getText("table-filter-filter"))));
};
const getColumnSelectProps = ({ dataIndex, filters }) => ({
	filterDropdown: (props) => /* @__PURE__ */ React.createElement(FilterDropdown, _objectSpread2(_objectSpread2({}, props), {}, { filters })),
	filterIcon: (filtered) => filtered ? /* @__PURE__ */ React.createElement(FilterFunnel01Fill, { style: {
		color: "#7f56d9",
		fontSize: 14
	} }) : /* @__PURE__ */ React.createElement(FilterFunnel01, { style: {
		color: "#98A2B3",
		fontSize: 14
	} })
});
//#endregion
export { getColumnSelectProps as default };
