import { getText } from "../../../../../locales/index.js";
import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import CellProvider from "./CellProvider/index.js";
import React, { useMemo } from "react";
import { Form, Tooltip } from "antd";
import { MenuOutlined } from "@ant-design/icons";
import classNames from "classnames";
import { useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
import "./index.less";
//#region src/components/table/Table/tableConfig/body/index.tsx
const _excluded = [
	"index",
	"__is_group",
	"children",
	"__is_drag_sort"
], _excluded2 = [
	"title",
	"editable",
	"children",
	"dataIndex",
	"field_type",
	"record",
	"handleSave",
	"lock",
	"render"
];
const EditableContext = React.createContext(null);
const EditableRow = (_ref) => {
	let { index, __is_group, children, __is_drag_sort } = _ref, props = _objectWithoutProperties(_ref, _excluded);
	const [form] = Form.useForm();
	const parentForm = Form.useFormInstance();
	const order_by = Form.useWatch("order_by", parentForm);
	const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ id: props["data-row-key"] });
	const style = _objectSpread2(_objectSpread2({}, props.style), {}, {
		transform: CSS.Transform.toString(transform && _objectSpread2(_objectSpread2({}, transform), {}, { scaleY: 1 })),
		transition
	}, isDragging && __is_drag_sort ? {
		position: "relative",
		zIndex: 9999
	} : {});
	const cells = useMemo(() => {
		if (__is_group) return children;
		return React.Children.map(children, (child) => {
			if (child.key === "__sort") {
				const handleIcon = order_by ? /* @__PURE__ */ React.createElement(Tooltip, { title: getText("table-column-drag-sort-disabled-tip") }, /* @__PURE__ */ React.createElement(MenuOutlined, { className: "pisell-lowcode-menu-out-lined-icon" })) : /* @__PURE__ */ React.createElement(MenuOutlined, _objectSpread2({
					ref: setActivatorNodeRef,
					className: "pisell-lowcode-menu-out-lined-icon"
				}, listeners));
				return React.cloneElement(child, { children: handleIcon });
			}
			return child;
		});
	}, [
		__is_group,
		children,
		order_by,
		setActivatorNodeRef,
		listeners
	]);
	return /* @__PURE__ */ React.createElement(Form, {
		form,
		component: false
	}, /* @__PURE__ */ React.createElement(EditableContext.Provider, { value: form }, __is_group && /* @__PURE__ */ React.createElement("tr", { style: { height: 12 } }), /* @__PURE__ */ React.createElement("tr", _objectSpread2(_objectSpread2({}, props), {}, {
		ref: setNodeRef,
		style
	}, attributes), cells)));
};
const EditableCell = (props) => {
	const { title, editable, children, dataIndex, field_type, record, handleSave, lock, render } = props, restProps = _objectWithoutProperties(props, _excluded2);
	return /* @__PURE__ */ React.createElement("td", _objectSpread2(_objectSpread2({}, restProps), {}, { className: classNames(restProps.className, "ant-table-cell", "materials-grid-table-cell") }), /* @__PURE__ */ React.createElement(CellProvider, props));
};
var body_default = {
	Row: EditableRow,
	Coll: EditableCell
};
//#endregion
export { EditableContext, body_default as default };
