import { createElement, Fragment } from "react";
import { Component, SugaredField, HasOne, HasMany } from "@contember/binding";
import { useDynamicMultipleChoiceField } from "./hooks/useDynamicMultipleChoiceField.js";
import { renderDynamicChoiceFieldStatic } from "./renderDynamicChoiceFieldStatic.js";
import { useDynamicMultipleChoiceWithConnectingEntityField } from "./hooks/useDynamicMultipleChoiceWithConnectingEntityField.js";
const DynamicMultiChoiceField = Component((props) => {
  const choiceFieldMetadata = "connectingEntityField" in props ? useDynamicMultipleChoiceWithConnectingEntityField(props) : useDynamicMultipleChoiceField(props);
  return props.children(choiceFieldMetadata);
}, (props, environment) => {
  let { subTree, renderedOption } = renderDynamicChoiceFieldStatic(props, environment);
  if ("connectingEntityField" in props) {
    const hasOneProps = typeof props.connectingEntityField === "string" ? { field: props.connectingEntityField } : props.connectingEntityField;
    renderedOption = /* @__PURE__ */ createElement(Fragment, null, props.sortableBy && /* @__PURE__ */ createElement(SugaredField, {
      field: props.sortableBy
    }), /* @__PURE__ */ createElement(HasOne, {
      ...hasOneProps
    }, renderedOption));
  }
  return /* @__PURE__ */ createElement(Fragment, null, subTree, /* @__PURE__ */ createElement(HasMany, {
    field: props.field,
    expectedMutation: "connectOrDisconnect",
    initialEntityCount: 0
  }, renderedOption));
}, "DynamicMultiChoiceField");
export { DynamicMultiChoiceField };
//# sourceMappingURL=DynamicMultiChoiceField.js.map
