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 { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { useMessageFormatter } from "../../../../../../i18n/useMessageFormatter.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/base/DataGridContainer/DataGridContainer.tsx";
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__ */ jsxDEV(Fragment, {
    children: [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
    })}`]
  }, void 0, true);
  return /* @__PURE__ */ jsxDEV(Stack, {
    direction: "vertical",
    className: `${componentClassName}-body`,
    children: [/* @__PURE__ */ jsxDEV(DataGridContainerHeader, {
      allowAggregateFilterControls,
      allowColumnVisibilityControls,
      hasTile: !!tile,
      accessor,
      pagingSummary,
      desiredState,
      setIsColumnHidden,
      setFilter,
      setLayout
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 60,
      columnNumber: 5
    }, void 0), tile && layout === "tiles" ? /* @__PURE__ */ jsxDEV(DataGridContainerGrid, {
      accessor,
      tile,
      tileSize
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 72,
      columnNumber: 8
    }, void 0) : /* @__PURE__ */ jsxDEV(DataGridContainerTable, {
      accessor,
      desiredState,
      displayedState,
      emptyMessage,
      emptyMessageComponent,
      onEntityClick,
      selectedEntityIds,
      setFilter,
      setOrderBy
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 77,
      columnNumber: 8
    }, void 0), !!normalizedItemCount && /* @__PURE__ */ jsxDEV(DataGridContainerFooter, {
      desiredState,
      pagesCount,
      pagingSummary,
      updatePaging
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 90,
      columnNumber: 6
    }, void 0)]
  }, void 0, true, {
    fileName: _jsxFileName,
    lineNumber: 59,
    columnNumber: 4
  }, void 0);
}, (props) => /* @__PURE__ */ jsxDEV(Fragment, {
  children: props.children
}, void 0, false), "DataGridContainer");
export {
  DataGridContainer
};
//# sourceMappingURL=DataGridContainer.js.map
