import { Field, EntityListSubTree } from "@contember/binding";
import { getDesugaredEntityList, getDesugaredFieldList } from "./hooks/useDesugaredOptionPath.js";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/fields/ChoiceField/renderDynamicChoiceFieldStatic.tsx";
const renderDynamicChoiceFieldStatic = (props, environment, filter) => {
  const searchByFields = props.searchByFields !== void 0 && (Array.isArray(props.searchByFields) ? props.searchByFields.map((field, i) => /* @__PURE__ */ jsxDEV(Field, {
    field
  }, i, false, {
    fileName: _jsxFileName,
    lineNumber: 13,
    columnNumber: 43
  }, void 0)) : /* @__PURE__ */ jsxDEV(Field, {
    field: props.searchByFields
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 15,
    columnNumber: 4
  }, void 0));
  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__ */ jsxDEV(Fragment, {
      children: [searchByFields, renderedOptionBase]
    }, void 0, true);
    const entityList = getDesugaredEntityList(props.options, environment, props.lazy, filter);
    const subTree = /* @__PURE__ */ jsxDEV(Fragment, {
      children: [/* @__PURE__ */ jsxDEV(EntityListSubTree, {
        entities: entityList,
        ...entityList,
        expectedMutation: "none",
        children: renderedOption
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 40,
        columnNumber: 5
      }, void 0), props.createNewForm && /* @__PURE__ */ jsxDEV(EntityListSubTree, {
        entities: {
          entityName: entityList.entityName
        },
        limit: 0,
        expectedMutation: "none",
        children: [props.createNewForm, renderedOption]
      }, void 0, true, {
        fileName: _jsxFileName,
        lineNumber: 44,
        columnNumber: 6
      }, void 0)]
    }, void 0, true);
    return {
      subTree,
      renderedOption
    };
  } else {
    const fieldList = getDesugaredFieldList(props.options, environment, props.lazy, filter);
    const renderedOptionBase = /* @__PURE__ */ jsxDEV(Field, {
      field: fieldList
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 59,
      columnNumber: 30
    }, void 0);
    const renderedOption = /* @__PURE__ */ jsxDEV(Fragment, {
      children: [searchByFields, renderedOptionBase]
    }, void 0, true);
    const subTree = /* @__PURE__ */ jsxDEV(Fragment, {
      children: [/* @__PURE__ */ jsxDEV(EntityListSubTree, {
        ...fieldList,
        entities: {
          entityName: fieldList.entityName,
          filter: fieldList.filter
        },
        expectedMutation: "none",
        children: renderedOption
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 69,
        columnNumber: 5
      }, void 0), props.createNewForm && /* @__PURE__ */ jsxDEV(EntityListSubTree, {
        entities: {
          entityName: fieldList.entityName
        },
        limit: 0,
        expectedMutation: "none",
        children: [props.createNewForm, searchByFields, renderedOptionBase]
      }, void 0, true, {
        fileName: _jsxFileName,
        lineNumber: 80,
        columnNumber: 6
      }, void 0)]
    }, void 0, true);
    return {
      subTree,
      renderedOption
    };
  }
};
export {
  renderDynamicChoiceFieldStatic
};
//# sourceMappingURL=renderDynamicChoiceFieldStatic.js.map
