"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const ui = require("@contember/ui");
const react = require("react");
const reactBindingUi = require("@contember/react-binding-ui");
const LayoutRenderer = require("../LayoutRenderer.cjs");
const ImmutableEntityListTablePageRenderer = reactBinding.Component(
  ({
    enableRemoving = true,
    children,
    tableProps,
    tableRowProps,
    accessor,
    emptyMessage,
    emptyMessageComponent,
    afterTitle,
    ...layoutProps
  }) => {
    return /* @__PURE__ */ jsxRuntime.jsx(
      LayoutRenderer.LayoutRenderer,
      {
        ...layoutProps,
        children: /* @__PURE__ */ jsxRuntime.jsx(TableRenderer, { accessor, ...{ emptyMessage, emptyMessageComponent }, ...tableProps, children: /* @__PURE__ */ jsxRuntime.jsx(TableRowRenderer, { ...tableRowProps, enableRemoving, children }) })
      }
    );
  },
  "ImmutableEntityListTablePageRenderer"
);
const TableRenderer = reactBinding.Component(
  ({ accessor, children, ...props }) => {
    const isEmpty = !Array.from(accessor).some((entity) => entity instanceof reactBinding.EntityAccessor && entity.existsOnServer);
    if (isEmpty) {
      return /* @__PURE__ */ jsxRuntime.jsx(reactBindingUi.EmptyMessage, { component: props.emptyMessageComponent, children: props.emptyMessage ?? "There are no items to display." });
    }
    return /* @__PURE__ */ jsxRuntime.jsx(ui.Table, { ...props, children: Array.from(accessor).map((it, i) => /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Entity, { accessor: it, children }, i)) });
  },
  ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }),
  "TableContainerRenderer"
);
const TableRowRenderer = react.memo((props) => /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { ...props, children: [
  props.children,
  props.enableRemoving && /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { shrunk: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactBindingUi.DeleteEntityButton, { immediatePersist: true }) })
] }));
ui.TableRow.displayName = "TableRowRenderer";
exports.ImmutableEntityListTablePageRenderer = ImmutableEntityListTablePageRenderer;
exports.TableRenderer = TableRenderer;
//# sourceMappingURL=ImmutableEntityListTablePageRenderer.cjs.map
