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);

// src/components/dataSourceComponents/dataSourceTable/hooks/useDesignMode.ts
var useDesignMode_exports = {};
__export(useDesignMode_exports, {
  default: () => useDesignMode_default
});
module.exports = __toCommonJS(useDesignMode_exports);
var import_react = require("react");
var useDesignMode = (props, { registerValueVariable, openDrawer, closeDrawer, data }) => {
  const {
    __designMode,
    componentId,
    operation
  } = props;
  const { items } = operation || {};
  const prevItemsRef = (0, import_react.useRef)([]);
  (0, import_react.useEffect)(() => {
    var _a;
    if (__designMode === "design" && (items == null ? void 0 : items.length) && ((_a = prevItemsRef.current) == null ? void 0 : _a.length)) {
      const changedItem = items.find((item) => {
        const prevItem = prevItemsRef.current.find((prev) => prev.key === item.key);
        if (!prevItem) return false;
        if (item.actionType !== prevItem.actionType) {
          return true;
        }
        return false;
      });
      if (changedItem) {
        if (["view", "edit", "custom"].includes(changedItem.actionType)) {
          registerValueVariable == null ? void 0 : registerValueVariable(componentId, {
            currentRecord: (data == null ? void 0 : data[0]) || null
          });
          openDrawer(changedItem);
        } else {
          closeDrawer();
        }
      }
    }
    prevItemsRef.current = items;
  }, [items, __designMode]);
};
var useDesignMode_default = useDesignMode;
