import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { Component, EntityAccessor, Entity } from "@contember/react-binding";
import { Table, TableRow, TableCell } from "@contember/ui";
import { memo } from "react";
import { EmptyMessage, DeleteEntityButton } from "@contember/react-binding-ui";
import { LayoutRenderer } from "../LayoutRenderer.js";
const ImmutableEntityListTablePageRenderer = Component(
  ({
    enableRemoving = true,
    children,
    tableProps,
    tableRowProps,
    accessor,
    emptyMessage,
    emptyMessageComponent,
    afterTitle,
    ...layoutProps
  }) => {
    return /* @__PURE__ */ jsxDEV(
      LayoutRenderer,
      {
        ...layoutProps,
        children: /* @__PURE__ */ jsxDEV(TableRenderer, { accessor, ...{ emptyMessage, emptyMessageComponent }, ...tableProps, children: /* @__PURE__ */ jsxDEV(TableRowRenderer, { ...tableRowProps, enableRemoving, children }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
          lineNumber: 34,
          columnNumber: 6
        }, void 0) }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
          lineNumber: 33,
          columnNumber: 5
        }, void 0)
      },
      void 0,
      false,
      {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
        lineNumber: 30,
        columnNumber: 4
      },
      void 0
    );
  },
  "ImmutableEntityListTablePageRenderer"
);
const TableRenderer = Component(
  ({ accessor, children, ...props }) => {
    const isEmpty = !Array.from(accessor).some((entity) => entity instanceof EntityAccessor && entity.existsOnServer);
    if (isEmpty) {
      return /* @__PURE__ */ jsxDEV(EmptyMessage, { component: props.emptyMessageComponent, children: props.emptyMessage ?? "There are no items to display." }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
        lineNumber: 59,
        columnNumber: 5
      }, void 0);
    }
    return /* @__PURE__ */ jsxDEV(Table, { ...props, children: Array.from(accessor).map((it, i) => /* @__PURE__ */ jsxDEV(Entity, { accessor: it, children }, i, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
      lineNumber: 66,
      columnNumber: 6
    }, void 0)) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
      lineNumber: 64,
      columnNumber: 4
    }, void 0);
  },
  ({ children }) => /* @__PURE__ */ jsxDEV(Fragment, { children }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
    lineNumber: 73,
    columnNumber: 20
  }, void 0),
  "TableContainerRenderer"
);
const TableRowRenderer = memo((props) => /* @__PURE__ */ jsxDEV(TableRow, { ...props, children: [
  props.children,
  props.enableRemoving && /* @__PURE__ */ jsxDEV(TableCell, { shrunk: true, children: /* @__PURE__ */ jsxDEV(DeleteEntityButton, { immediatePersist: true }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
    lineNumber: 89,
    columnNumber: 5
  }, void 0) }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
    lineNumber: 88,
    columnNumber: 4
  }, void 0)
] }, void 0, true, {
  fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/renderers/pageRenderers/ImmutableEntityListTablePageRenderer.tsx",
  lineNumber: 85,
  columnNumber: 2
}, void 0));
TableRow.displayName = "TableRowRenderer";
export {
  ImmutableEntityListTablePageRenderer,
  TableRenderer
};
//# sourceMappingURL=ImmutableEntityListTablePageRenderer.js.map
