import { createElement, Fragment } from "react";
import { Field, EntityListSubTree, NIL_UUID } from "@contember/binding";
import { getDesugaredEntityList, getDesugaredFieldList } from "./hooks/useDesugaredOptionPath.js";
const renderDynamicChoiceFieldStatic = (props, environment, filter) => {
  const searchByFields = props.searchByFields !== void 0 && (Array.isArray(props.searchByFields) ? props.searchByFields.map((field, i) => /* @__PURE__ */ createElement(Field, {
    field,
    key: i
  })) : /* @__PURE__ */ createElement(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__ */ createElement(Fragment, null, searchByFields, renderedOptionBase);
    const entityList = getDesugaredEntityList(props.options, environment, props.lazy, filter);
    const subTree = /* @__PURE__ */ createElement(Fragment, null, /* @__PURE__ */ createElement(EntityListSubTree, {
      entities: entityList,
      ...entityList,
      expectedMutation: "none"
    }, renderedOption), props.createNewForm && /* @__PURE__ */ createElement(EntityListSubTree, {
      entities: {
        entityName: entityList.entityName,
        filter: { id: { eq: NIL_UUID } }
      },
      expectedMutation: "none"
    }, props.createNewForm, renderedOption));
    return { subTree, renderedOption };
  } else {
    const fieldList = getDesugaredFieldList(props.options, environment, props.lazy, filter);
    const renderedOptionBase = /* @__PURE__ */ createElement(Field, {
      field: fieldList
    });
    const renderedOption = /* @__PURE__ */ createElement(Fragment, null, searchByFields, renderedOptionBase);
    const subTree = /* @__PURE__ */ createElement(Fragment, null, /* @__PURE__ */ createElement(EntityListSubTree, {
      ...fieldList,
      entities: {
        entityName: fieldList.entityName,
        filter: fieldList.filter
      },
      expectedMutation: "none"
    }, renderedOption), props.createNewForm && /* @__PURE__ */ createElement(EntityListSubTree, {
      entities: {
        entityName: fieldList.entityName,
        filter: { id: { eq: NIL_UUID } }
      },
      expectedMutation: "none"
    }, props.createNewForm, searchByFields, renderedOptionBase));
    return { subTree, renderedOption };
  }
};
export { renderDynamicChoiceFieldStatic };
//# sourceMappingURL=renderDynamicChoiceFieldStatic.js.map
