import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { Component, useEntity, useEnvironment, QueryLanguage, Field } from "@contember/binding";
import { useMemo } from "react";
import { FieldFallbackView } from "./FieldFallbackView.js";
const CoalesceFieldView = Component(
  (props) => {
    const entity = useEntity();
    const environment = useEnvironment();
    const desugaredFields = useMemo(
      () => props.fields.map((it) => QueryLanguage.desugarRelativeSingleField(it, environment)),
      // eslint-disable-next-line react-hooks/exhaustive-deps
      [environment, ...props.fields]
    );
    let value = null;
    for (const field of desugaredFields) {
      value = entity.getRelativeSingleField(field).value;
      if (value !== null) {
        break;
      }
    }
    if (value === null) {
      return /* @__PURE__ */ jsxDEV(FieldFallbackView, { fallback: props.fallback, fallbackStyle: props.fallbackStyle }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fieldViews/CoalesceFieldView.tsx",
        lineNumber: 38,
        columnNumber: 11
      }, globalThis);
    }
    if (props.format) {
      return /* @__PURE__ */ jsxDEV(Fragment, { children: props.format(value) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fieldViews/CoalesceFieldView.tsx",
        lineNumber: 41,
        columnNumber: 11
      }, globalThis);
    }
    return /* @__PURE__ */ jsxDEV(Fragment, { children: value }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fieldViews/CoalesceFieldView.tsx",
      lineNumber: 43,
      columnNumber: 10
    }, globalThis);
  },
  (props) => {
    return /* @__PURE__ */ jsxDEV(Fragment, { children: props.fields.map((it, i) => /* @__PURE__ */ jsxDEV(Field, { field: it }, i, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fieldViews/CoalesceFieldView.tsx",
      lineNumber: 49,
      columnNumber: 6
    }, globalThis)) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/fieldViews/CoalesceFieldView.tsx",
      lineNumber: 47,
      columnNumber: 4
    }, globalThis);
  }
);
export {
  CoalesceFieldView
};
//# sourceMappingURL=CoalesceFieldView.js.map
