const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
//#region src/components/listComponent/index.tsx
const ListComponent = ({ value = [], onChange = () => {}, renderItem = () => null, renderAddButton = () => null, createItem = (item) => item, maxLength = 999, rowKey = "_id", className, style, wrapClassName }, ref) => {
	const handleAddItem = (item) => {
		if (value.length < maxLength) onChange([...value, createItem(require_objectSpread2._objectSpread2({ [rowKey]: (0, _pisell_utils.getUniqueId)() }, item))]);
	};
	const handleOnChangeItem = (item, newValue) => {
		onChange(value.map((d) => {
			if (d[rowKey] === item[rowKey]) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d), newValue);
			return d;
		}));
	};
	const handleDeleteItem = (current) => {
		onChange(value.filter((item) => item[rowKey] !== current[rowKey]));
	};
	(0, react.useImperativeHandle)(ref, () => {
		return {
			add: handleAddItem,
			delete: handleDeleteItem
		};
	});
	return /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("list-component-wrap", wrapClassName) }, /* @__PURE__ */ react.default.createElement("ul", {
		className: (0, classnames.default)("list-component-ul", className),
		style
	}, value.map((item, index) => renderItem(item, index, handleDeleteItem, handleOnChangeItem))), value.length < maxLength && renderAddButton(handleAddItem));
};
var listComponent_default = (0, react.forwardRef)(ListComponent);
//#endregion
exports.default = listComponent_default;
