import { useMemo, createElement } from "react";
import { Component, useEnvironment } from "@contember/binding";
import { ContainerSpinner } from "@contember/ui";
import { useDataGridDisplayedState } from "../base/useDataGridDisplayedState.js";
import { renderGrid } from "./renderGrid.js";
const ControlledDataGrid = Component(({ state, stateMethods, ...props }) => {
  const containerProps = useMemo(() => ({
    emptyMessage: props.emptyMessage,
    emptyMessageComponent: props.emptyMessageComponent,
    emptyMessageComponentExtraProps: props.emptyMessageComponentExtraProps,
    onEntityClick: props.onEntityClick,
    selectedEntityIds: props.selectedEntityIds,
    tile: props.tile
  }), [
    props.emptyMessage,
    props.emptyMessageComponent,
    props.emptyMessageComponentExtraProps,
    props.onEntityClick,
    props.selectedEntityIds,
    props.tile
  ]);
  const displayedState = useDataGridDisplayedState(stateMethods, state, props.tile);
  const environment = useEnvironment();
  if (!displayedState.gridState) {
    return /* @__PURE__ */ createElement(ContainerSpinner, null);
  }
  return renderGrid(stateMethods, displayedState.treeRootId, displayedState.gridState, state, environment, containerProps, "component" in props ? props.component : void 0, "componentProps" in props ? props.componentProps : void 0);
}, ({ state, stateMethods, ...props }, environment) => {
  return renderGrid(stateMethods, void 0, state, state, environment, {
    tile: props.tile
  }, "component" in props ? props.component : void 0, "componentProps" in props ? props.componentProps : void 0);
}, "ControlledDataGrid");
export { ControlledDataGrid };
//# sourceMappingURL=ControlledDataGrid.js.map
