import { Field, EntityListSubTree } from "@contember/binding";
import { getDesugaredEntityList, getDesugaredFieldList } from "./hooks/useDesugaredOptionPath.js";
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
const renderDynamicChoiceFieldStatic = (props, environment, filter) => {
  const searchByFields = props.searchByFields !== void 0 && (Array.isArray(props.searchByFields) ? props.searchByFields.map((field, i) => /* @__PURE__ */ jsx(Field, {
    field
  }, i)) : /* @__PURE__ */ jsx(Field, {
    field: props.searchByFields
  }));
  if ("renderOption" in props || "optionLabel" in props) {
    let renderedOptionBase;
    if ("renderOption" in props) {
      renderedOptionBase = typeof props.optionsStaticRender === "function" ? props.optionsStaticRender(environment) : props.optionsStaticRender;
    } else {
      renderedOptionBase = props.optionLabel;
    }
    const renderedOption = /* @__PURE__ */ jsxs(Fragment, {
      children: [searchByFields, renderedOptionBase]
    });
    const entityList = getDesugaredEntityList(props.options, environment, props.lazy, filter);
    const subTree = /* @__PURE__ */ jsxs(Fragment, {
      children: [/* @__PURE__ */ jsx(EntityListSubTree, {
        entities: entityList,
        ...entityList,
        expectedMutation: "none",
        children: renderedOption
      }), props.createNewForm && /* @__PURE__ */ jsxs(EntityListSubTree, {
        entities: {
          entityName: entityList.entityName
        },
        limit: 0,
        expectedMutation: "none",
        children: [props.createNewForm, renderedOption]
      })]
    });
    return {
      subTree,
      renderedOption
    };
  } else {
    const fieldList = getDesugaredFieldList(props.options, environment, props.lazy, filter);
    const renderedOptionBase = /* @__PURE__ */ jsx(Field, {
      field: fieldList
    });
    const renderedOption = /* @__PURE__ */ jsxs(Fragment, {
      children: [searchByFields, renderedOptionBase]
    });
    const subTree = /* @__PURE__ */ jsxs(Fragment, {
      children: [/* @__PURE__ */ jsx(EntityListSubTree, {
        ...fieldList,
        entities: {
          entityName: fieldList.entityName,
          filter: fieldList.filter
        },
        expectedMutation: "none",
        children: renderedOption
      }), props.createNewForm && /* @__PURE__ */ jsxs(EntityListSubTree, {
        entities: {
          entityName: fieldList.entityName
        },
        limit: 0,
        expectedMutation: "none",
        children: [props.createNewForm, searchByFields, renderedOptionBase]
      })]
    });
    return {
      subTree,
      renderedOption
    };
  }
};
export {
  renderDynamicChoiceFieldStatic
};
//# sourceMappingURL=renderDynamicChoiceFieldStatic.js.map
