var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/dataSourceComponents/dataSourceForm/formItem.tsx
var formItem_exports = {};
__export(formItem_exports, {
  default: () => formItem_default
});
module.exports = __toCommonJS(formItem_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_useDataSource = __toESM(require("../hooks/useDataSource"));
var import_useFormSetting = __toESM(require("./provider/hooks/useFormSetting"));
var import_form = __toESM(require("../../form"));
var import_useJsonPrefixPath = __toESM(require("./provider/hooks/useJsonPrefixPath"));
var import_utils2 = require("./utils");
var FormItem = (props) => {
  var _a;
  const { children, name, label: propsLabel, mode: propsMode, ...other } = props;
  const { path: prefixPath = [] } = (0, import_useJsonPrefixPath.default)();
  const { dataSource } = (0, import_useDataSource.default)();
  const fields = dataSource == null ? void 0 : dataSource.fields;
  const { mode: globalMode } = (0, import_useFormSetting.default)();
  const field = fields == null ? void 0 : fields.find((item) => item.name === name);
  const label = propsLabel || ((_a = field == null ? void 0 : field.uiSchema) == null ? void 0 : _a.title) || name;
  const effectiveMode = propsMode || globalMode;
  const renderChildren = (0, import_react.useMemo)(() => {
    if ((0, import_utils.isArr)(children) && children.every(import_react.isValidElement)) {
      return children.map(
        (c) => (0, import_react.cloneElement)(c, { renderMode: effectiveMode })
      );
    }
    return children;
  }, [children, effectiveMode]);
  const concatName = name !== void 0 ? [...prefixPath, ...(0, import_utils2.toArr)(name)] : void 0;
  return /* @__PURE__ */ import_react.default.createElement(import_form.default.Item, { name: concatName, label, ...other }, renderChildren);
};
var formItem_default = FormItem;
