"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var useTableFormFieldRefs_exports = {};
__export(useTableFormFieldRefs_exports, {
  useTableFormFieldRefs: () => useTableFormFieldRefs
});
module.exports = __toCommonJS(useTableFormFieldRefs_exports);
var import_react = require("react");
var import_box_models = require("../../state/modules/box-models");
var import_react2 = require("../../runtimes/react");
function useTableFormFieldRefs(propController, { fieldsCount }) {
  const [container, setContainer] = (0, import_react.useState)(null);
  const [items, setItems] = (0, import_react.useState)(
    Array(fieldsCount + 1).fill(null)
  );
  const isInBuilder = (0, import_react2.useIsInBuilder)();
  (0, import_react.useEffect)(() => {
    if (!isInBuilder)
      return;
    let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest);
    return () => {
      cancelAnimationFrame(animationFrameHandle);
    };
    function handleAnimationFrameRequest() {
      if (propController == null)
        return;
      if (container != null)
        propController.tableFormLayoutChange({ layout: (0, import_box_models.getBox)(container) });
      items.map((item, index) => {
        if (item == null)
          return;
        propController.tableFormFieldLayoutChange({ index, layout: (0, import_box_models.getBox)(item) });
      });
      animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest);
    }
  }, [propController, container, items, isInBuilder]);
  const itemRefs = (0, import_react.useMemo)(
    () => Array.from({ length: fieldsCount + 1 }).map(
      (_, index) => (item) => {
        setItems((is) => [...is.slice(0, index), item, ...is.slice(index + 1)]);
      }
    ),
    [fieldsCount, setItems]
  );
  return { container: setContainer, items: itemRefs };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useTableFormFieldRefs
});
//# sourceMappingURL=useTableFormFieldRefs.js.map