import { createElement, Fragment, memo } from "react";
import { Component, EntityAccessor, Entity } from "@contember/binding";
import { Table, TableRow, TableCell } from "@contember/ui";
import { LayoutRenderer } from "../LayoutRenderer.js";
import { EmptyMessage } from "../../collections/helpers/EmptyMessage.js";
import { DeleteEntityButton } from "../../collections/helpers/DeleteEntityButton.js";
const ImmutableEntityListTablePageRenderer = Component(({
  enableRemoving = true,
  children,
  tableProps,
  tableRowProps,
  accessor,
  emptyMessage,
  emptyMessageComponent,
  afterTitle,
  ...layoutProps
}) => {
  return /* @__PURE__ */ createElement(LayoutRenderer, {
    ...layoutProps
  }, /* @__PURE__ */ createElement(TableRenderer, {
    accessor,
    ...{ emptyMessage, emptyMessageComponent },
    ...tableProps
  }, /* @__PURE__ */ createElement(TableRowRenderer, {
    ...tableRowProps,
    enableRemoving
  }, children)));
}, "ImmutableEntityListTablePageRenderer");
const TableRenderer = Component(({ accessor, children, ...props }) => {
  const isEmpty = !Array.from(accessor).some((entity) => entity instanceof EntityAccessor && entity.existsOnServer);
  if (isEmpty) {
    return /* @__PURE__ */ createElement(EmptyMessage, {
      component: props.emptyMessageComponent
    }, props.emptyMessage ?? "There are no items to display.");
  }
  return /* @__PURE__ */ createElement(Table, {
    ...props
  }, Array.from(accessor).map((it, i) => /* @__PURE__ */ createElement(Entity, {
    key: i,
    accessor: it
  }, children)));
}, ({ children }) => /* @__PURE__ */ createElement(Fragment, null, children), "TableContainerRenderer");
const TableRowRenderer = memo((props) => /* @__PURE__ */ createElement(TableRow, {
  ...props
}, props.children, props.enableRemoving && /* @__PURE__ */ createElement(TableCell, {
  shrunk: true
}, /* @__PURE__ */ createElement(DeleteEntityButton, {
  immediatePersist: true
}))));
TableRow.displayName = "TableRowRenderer";
export { ImmutableEntityListTablePageRenderer };
//# sourceMappingURL=ImmutableEntityListTablePageRenderer.js.map
