import { getText } from "../../../../../locales/index.js";
import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import Sortable from "../../../../DragSortList/index.js";
import { isFixedOrderValid } from "./utils.js";
import React from "react";
import { Tooltip } from "antd";
import { EyeInvisibleOutlined, EyeOutlined } from "@ant-design/icons";
import classNames from "classnames";
import DotsSix from "@pisell/icon/es/DotsSix";
import Lock01 from "@pisell/icon/es/Lock01";
import "./PopoverContent.less";
//#region src/components/table/Actions/component/ColumnsSetting/PopoverContent.tsx
const prefix = "pisell-lowcode-";
const DragItem = React.forwardRef((props, ref) => {
	const { attributes, listeners, setActivatorNodeRef, style, isLock } = props;
	return /* @__PURE__ */ React.createElement("div", _objectSpread2(_objectSpread2({ ref }, attributes), {}, {
		style,
		className: `${prefix}table-action-column-drag-item`
	}), isLock ? /* @__PURE__ */ React.createElement(Tooltip, { title: getText("table-column-group-lock-tip") }, /* @__PURE__ */ React.createElement(Lock01, { className: `${prefix}table-action-column-drag-bar` })) : /* @__PURE__ */ React.createElement(DotsSix, _objectSpread2(_objectSpread2({ ref: setActivatorNodeRef }, listeners), {}, {
		style: _objectSpread2(_objectSpread2({}, listeners.style || {}), {}, { touchAction: "none" }),
		className: `${prefix}table-action-column-drag-bar`
	})), props.children);
});
const defaultValue = [];
const PopoverContent = (props) => {
	const { value = defaultValue, onChange, isShowTitle = true, headerContent } = props;
	const handleChange = (index, isShow) => {
		value[index] = _objectSpread2(_objectSpread2({}, value[index]), {}, { isShow });
		onChange === null || onChange === void 0 || onChange([...value]);
	};
	return /* @__PURE__ */ React.createElement("div", { className: `${prefix}table-action-column-popover-content-wrap` }, /* @__PURE__ */ React.createElement("div", { className: `${prefix}table-action-column-header` }, isShowTitle && /* @__PURE__ */ React.createElement("span", { className: `${prefix}table-action-column-header-title` }, getText("table-action-column-title")), headerContent && headerContent), /* @__PURE__ */ React.createElement("div", { className: `${prefix}table-action-column-content` }, /* @__PURE__ */ React.createElement(Sortable, {
		list: value,
		rowKey: (item) => {
			var _item$dataIndex;
			return `${item.key}-${(_item$dataIndex = item.dataIndex) === null || _item$dataIndex === void 0 ? void 0 : _item$dataIndex.toString()}`;
		},
		onChange: (list) => {
			if (!isFixedOrderValid(list)) return;
			onChange === null || onChange === void 0 || onChange(list.map((item, index) => _objectSpread2(_objectSpread2({}, item), {}, { sortIndex: index })));
		}
	}, ({ item, index, style, props, attributes, setActivatorNodeRef, listeners }) => {
		return /* @__PURE__ */ React.createElement(DragItem, _objectSpread2(_objectSpread2({}, props), {}, {
			isLock: item.fixed,
			index,
			attributes,
			setActivatorNodeRef,
			listeners,
			style
		}), /* @__PURE__ */ React.createElement("div", { className: `${prefix}table-action-column-drag-item-right` }, /* @__PURE__ */ React.createElement("span", { className: classNames(`${prefix}table-action-column-drag-item-right-text`, { [`${prefix}table-action-column-drag-item-right-text-hidden`]: !item.isShow }) }, item.titleString || item.title), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("span", {
			className: `${prefix}table-action-column-drag-item-right-icon-wrap`,
			onClick: () => {
				handleChange(index, !item.isShow);
			}
		}, item.isShow ? /* @__PURE__ */ React.createElement(EyeOutlined, null) : /* @__PURE__ */ React.createElement(EyeInvisibleOutlined, null)))));
	})));
};
//#endregion
export { PopoverContent as default };
