import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { Component, HasOne, HasMany, SugaredField } 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 && props.connectingEntityField ? useDynamicMultipleChoiceWithConnectingEntityField(props) : useDynamicMultipleChoiceField(props);
    return props.children(choiceFieldMetadata);
  },
  (props, environment) => {
    let { subTree, renderedOption } = renderDynamicChoiceFieldStatic(props, environment);
    let expectedMutation = "connectOrDisconnect";
    if ("connectingEntityField" in props && props.connectingEntityField) {
      expectedMutation = "anyMutation";
      const hasOneProps = typeof props.connectingEntityField === "string" ? { field: props.connectingEntityField } : props.connectingEntityField;
      renderedOption = /* @__PURE__ */ jsxDEV(Fragment, { children: /* @__PURE__ */ jsxDEV(HasOne, { ...hasOneProps, expectedMutation: "connectOrDisconnect", children: renderedOption }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fields/ChoiceField/DynamicMultiChoiceField.tsx",
        lineNumber: 29,
        columnNumber: 6
      }, globalThis) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fields/ChoiceField/DynamicMultiChoiceField.tsx",
        lineNumber: 28,
        columnNumber: 22
      }, globalThis);
    }
    return /* @__PURE__ */ jsxDEV(Fragment, { children: [
      subTree,
      /* @__PURE__ */ jsxDEV(HasMany, { field: props.field, expectedMutation, initialEntityCount: 0, children: [
        props.sortableBy && /* @__PURE__ */ jsxDEV(SugaredField, { field: props.sortableBy }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fields/ChoiceField/DynamicMultiChoiceField.tsx",
          lineNumber: 39,
          columnNumber: 28
        }, globalThis),
        renderedOption
      ] }, void 0, true, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fields/ChoiceField/DynamicMultiChoiceField.tsx",
        lineNumber: 38,
        columnNumber: 6
      }, globalThis)
    ] }, void 0, true, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fields/ChoiceField/DynamicMultiChoiceField.tsx",
      lineNumber: 36,
      columnNumber: 5
    }, globalThis);
  },
  "DynamicMultiChoiceField"
);
export {
  DynamicMultiChoiceField
};
//# sourceMappingURL=DynamicMultiChoiceField.js.map
