const require_runtime = require("../../../_virtual/_rolldown/runtime.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 = require("../../form/index.js");
const require_useDataSource = require("../hooks/useDataSource.js");
const require_useFormSetting = require("./provider/hooks/useFormSetting.js");
const require_useJsonPrefixPath = require("./provider/hooks/useJsonPrefixPath.js");
const require_utils = require("./utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
//#region src/components/dataSourceComponents/dataSourceForm/formItem.tsx
const _excluded = [
	"children",
	"name",
	"label",
	"mode"
];
const FormItem = (props) => {
	var _field$uiSchema;
	const { children, name, label: propsLabel, mode: propsMode } = props, other = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const { path: prefixPath = [] } = require_useJsonPrefixPath.default();
	const { dataSource } = require_useDataSource.default();
	const fields = dataSource === null || dataSource === void 0 ? void 0 : dataSource.fields;
	const { renderMode: globalMode } = require_useFormSetting.default();
	const field = fields === null || fields === void 0 ? void 0 : fields.find((item) => item.name === name);
	const label = propsLabel || (field === null || field === void 0 || (_field$uiSchema = field.uiSchema) === null || _field$uiSchema === void 0 ? void 0 : _field$uiSchema.title) || name;
	const effectiveMode = propsMode || globalMode;
	const renderChildren = (0, react.useMemo)(() => {
		if ((0, _pisell_utils.isArr)(children) && children.every(react.isValidElement)) return children.map((c) => (0, react.cloneElement)(c, { renderMode: effectiveMode }));
		return children;
	}, [children, effectiveMode]);
	const concatName = name !== void 0 ? [...prefixPath, ...require_utils.toArr(name)] : void 0;
	return /* @__PURE__ */ react.default.createElement(require_index.default.Item, require_objectSpread2._objectSpread2({
		name: concatName,
		label
	}, other), renderChildren);
};
//#endregion
exports.default = FormItem;
