import { Component, useEntity, useEnvironment, QueryLanguage, Field } from "@contember/binding";
import { useMemo } from "react";
import { FieldFallbackView } from "./FieldFallbackView.js";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/fieldViews/CoalesceFieldView.tsx";
const CoalesceFieldView = Component((props) => {
  const entity = useEntity();
  const environment = useEnvironment();
  const desugaredFields = useMemo(
    () => props.fields.map((it) => QueryLanguage.desugarRelativeSingleField(it, environment)),
    [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: _jsxFileName,
      lineNumber: 35,
      columnNumber: 11
    }, void 0);
  }
  if (props.format) {
    return /* @__PURE__ */ jsxDEV(Fragment, {
      children: props.format(value)
    }, void 0, false);
  }
  return /* @__PURE__ */ jsxDEV(Fragment, {
    children: value
  }, void 0, false);
}, (props) => {
  return /* @__PURE__ */ jsxDEV(Fragment, {
    children: props.fields.map((it, i) => /* @__PURE__ */ jsxDEV(Field, {
      field: it
    }, i, false, {
      fileName: _jsxFileName,
      lineNumber: 46,
      columnNumber: 6
    }, void 0))
  }, void 0, false);
});
export {
  CoalesceFieldView
};
//# sourceMappingURL=CoalesceFieldView.js.map
