import { useState, useEffect } from "react";
import { renderGrid } from "../grid/renderGrid.js";
import { useEnvironment, useExtendTree } from "@contember/binding";
const useDataGridDisplayedState = (stateMethods, desiredState, tile) => {
  const [displayedState, setDisplayedState] = useState({
    gridState: void 0,
    treeRootId: void 0
  });
  const environment = useEnvironment();
  const extendTree = useExtendTree();
  useEffect(() => {
    (async () => {
      if (displayedState.gridState === desiredState) {
        return;
      }
      const newTreeRootId = await extendTree(renderGrid(stateMethods, void 0, desiredState, desiredState, environment, {
        tile
      }));
      if (newTreeRootId) {
        setDisplayedState({
          gridState: desiredState,
          treeRootId: newTreeRootId
        });
      }
    })();
  }, [desiredState, displayedState, environment, extendTree, stateMethods, tile]);
  return displayedState;
};
export { useDataGridDisplayedState };
//# sourceMappingURL=useDataGridDisplayedState.js.map
