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