import { jsx, Fragment, jsxs } from "react/jsx-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__ */ jsx(
      LayoutRenderer,
      {
        ...layoutProps,
        children: /* @__PURE__ */ jsx(TableRenderer, { accessor, ...{ emptyMessage, emptyMessageComponent }, ...tableProps, children: /* @__PURE__ */ jsx(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__ */ jsx(EmptyMessage, { component: props.emptyMessageComponent, children: props.emptyMessage ?? "There are no items to display." });
    }
    return /* @__PURE__ */ jsx(Table, { ...props, children: Array.from(accessor).map((it, i) => /* @__PURE__ */ jsx(Entity, { accessor: it, children }, i)) });
  },
  ({ children }) => /* @__PURE__ */ jsx(Fragment, { children }),
  "TableContainerRenderer"
);
const TableRowRenderer = memo((props) => /* @__PURE__ */ jsxs(TableRow, { ...props, children: [
  props.children,
  props.enableRemoving && /* @__PURE__ */ jsx(TableCell, { shrunk: true, children: /* @__PURE__ */ jsx(DeleteEntityButton, { immediatePersist: true }) })
] }));
TableRow.displayName = "TableRowRenderer";
export {
  ImmutableEntityListTablePageRenderer,
  TableRenderer
};
//# sourceMappingURL=ImmutableEntityListTablePageRenderer.js.map
