import { createElement, Fragment } from "react";
import { Component } from "@contember/binding";
import { useComponentClassName, Stack } from "@contember/ui";
import { dataGridDictionary } from "../dataGridDictionary.js";
import { useDataGridTotalCount } from "../useDataGridTotalCount.js";
import { DataGridContainerFooter } from "./DataGridContainerFooter.js";
import { DataGridContainerGrid } from "./DataGridContainerGrid.js";
import { DataGridContainerHeader } from "./DataGridContainerHeader.js";
import { DataGridContainerTable } from "./DataGridContainerTable.js";
import { useMessageFormatter } from "../../../../../../i18n/useMessageFormatter.js";
const DataGridContainer = Component(({
  accessor,
  allowAggregateFilterControls,
  allowColumnVisibilityControls,
  desiredState,
  displayedState,
  emptyMessage,
  emptyMessageComponent,
  entityName,
  filter,
  onEntityClick,
  selectedEntityIds,
  setFilter,
  setIsColumnHidden,
  setLayout,
  setOrderBy,
  tile,
  tileSize,
  updatePaging
}) => {
  const componentClassName = useComponentClassName("data-grid");
  const {
    paging: { pageIndex, itemsPerPage },
    layout
  } = desiredState;
  const formatMessage = useMessageFormatter(dataGridDictionary);
  const totalCount = useDataGridTotalCount(entityName, filter);
  const normalizedItemCount = itemsPerPage === null ? accessor.length : totalCount;
  const pagesCount = totalCount !== void 0 && itemsPerPage !== null ? Math.ceil(totalCount / itemsPerPage) : void 0;
  const pagingSummary = /* @__PURE__ */ createElement(Fragment, null, pagesCount === void 0 ? formatMessage("dataGrid.paging.status.unknownPageTotal", { pageNumber: pageIndex + 1 }) : formatMessage("dataGrid.paging.status.knownPageTotal", {
    pageNumber: pageIndex + 1,
    totalPageCount: pagesCount
  }), normalizedItemCount !== void 0 && ` ${formatMessage("dataGrid.paging.status.itemCount", { itemCount: normalizedItemCount })}`);
  return /* @__PURE__ */ createElement(Stack, {
    direction: "vertical",
    className: `${componentClassName}-body`
  }, /* @__PURE__ */ createElement(DataGridContainerHeader, {
    allowAggregateFilterControls,
    allowColumnVisibilityControls,
    hasTile: !!tile,
    accessor,
    pagingSummary,
    desiredState,
    setIsColumnHidden,
    setFilter,
    setLayout
  }), tile && layout === "tiles" ? /* @__PURE__ */ createElement(DataGridContainerGrid, {
    accessor,
    tile,
    tileSize
  }) : /* @__PURE__ */ createElement(DataGridContainerTable, {
    accessor,
    desiredState,
    displayedState,
    emptyMessage,
    emptyMessageComponent,
    onEntityClick,
    selectedEntityIds,
    setFilter,
    setOrderBy
  }), !!normalizedItemCount && /* @__PURE__ */ createElement(DataGridContainerFooter, {
    desiredState,
    pagesCount,
    pagingSummary,
    updatePaging
  }));
}, (props) => /* @__PURE__ */ createElement(Fragment, null, props.children), "DataGridContainer");
export { DataGridContainer };
//# sourceMappingURL=DataGridContainer.js.map
