"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 micro_iframe_app_exports = {};
__export(micro_iframe_app_exports, {
  MicroIFrameApp: () => MicroIFrameApp
});
module.exports = __toCommonJS(micro_iframe_app_exports);
var import_react = require("react");
var import_react2 = require("react");
var import_use_previous = require("../use-previous.js");
var import_app = require("./app.js");
const MicroIFrameApp = (0, import_react2.memo)(({ entityId = null, ...rest }) => {
  const [disposePrevApp, setDisposePrevApp] = (0, import_react2.useState)(false);
  const [appKey, setAppKey] = (0, import_react2.useState)(Date.now());
  const uuid = (0, import_react2.useId)();
  const prevEntityId = (0, import_use_previous.usePrevious)(entityId);
  (0, import_react2.useEffect)(() => {
    if (prevEntityId !== entityId && prevEntityId) {
      setDisposePrevApp(true);
    }
  }, [entityId]);
  return /* @__PURE__ */ (0, import_react.createElement)(
    import_app.App,
    {
      ...rest,
      uuid,
      key: appKey,
      dispose: disposePrevApp,
      onUnloadComplete: () => {
        setAppKey(Date.now());
        setDisposePrevApp(false);
      }
    }
  );
});
