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