import { createElement } from "react";
import { useEffect, useState, memo, useId } from "react";
import { usePrevious } from "../use-previous.js";
import { App } from "./app.js";
const MicroIFrameApp = memo(({ entityId = null, ...rest }) => {
  const [disposePrevApp, setDisposePrevApp] = useState(false);
  const [appKey, setAppKey] = useState(Date.now());
  const uuid = useId();
  const prevEntityId = usePrevious(entityId);
  useEffect(() => {
    if (prevEntityId !== entityId && prevEntityId) {
      setDisposePrevApp(true);
    }
  }, [entityId]);
  return /* @__PURE__ */ createElement(
    App,
    {
      ...rest,
      uuid,
      key: appKey,
      dispose: disposePrevApp,
      onUnloadComplete: () => {
        setAppKey(Date.now());
        setDisposePrevApp(false);
      }
    }
  );
});
export {
  MicroIFrameApp
};
