import { createElement, Fragment } from "react";
import { Component } from "@contember/binding";
import { AddNewBlockButton } from "./AddNewBlockButton.js";
import { SortableBlock } from "./SortableBlock.js";
import { useNormalizedBlocks } from "../../blocks/useNormalizedBlocks.js";
import { Repeater } from "../Repeater/Repeater.js";
import { DiscriminatedBlocks } from "../../blocks/DiscriminatedBlocks.js";
const BlockRepeater = Component(({ discriminationField, ...props }) => {
  const normalizedBlocks = useNormalizedBlocks(props.children);
  const extraProps = {
    normalizedBlocks,
    discriminationField
  };
  return /* @__PURE__ */ createElement(Repeater, {
    ...props,
    addButtonComponent: AddNewBlockButton,
    addButtonComponentExtraProps: extraProps,
    itemComponent: SortableBlock,
    itemComponentExtraProps: extraProps
  }, /* @__PURE__ */ createElement(Fragment, null));
}, (props) => /* @__PURE__ */ createElement(Repeater, {
  ...props,
  initialEntityCount: 0
}, typeof props.discriminationField === "string" && /* @__PURE__ */ createElement(DiscriminatedBlocks, {
  field: props.discriminationField,
  label: props.label
}, props.children), typeof props.discriminationField === "string" || /* @__PURE__ */ createElement(DiscriminatedBlocks, {
  ...props.discriminationField,
  label: props.label
}, props.children)), "SortableBlockRepeater");
export { BlockRepeater };
//# sourceMappingURL=BlockRepeater.js.map
