import { createElement } from "react";
import { Component, QueryLanguage, wrapFilterInHasOnes } from "@contember/binding";
import { createGenericTextCellFilterCondition, GenericTextCellFilter } from "./GenericTextCellFilter.js";
import { Stack } from "@contember/ui";
import { CoalesceFieldView } from "../../../fieldViews/CoalesceFieldView.js";
import { DataGridColumn } from "../base/DataGridColumn.js";
const CoalesceTextCell = Component((props) => {
  return /* @__PURE__ */ createElement(DataGridColumn, {
    ...props,
    enableOrdering: false,
    getNewFilter: (filter, { environment }) => {
      if (filter.query === "") {
        return void 0;
      }
      const condition = createGenericTextCellFilterCondition(filter);
      const parts = [];
      for (const field of props.fields) {
        const desugared = QueryLanguage.desugarRelativeSingleField({ field }, environment);
        const fieldCondition = wrapFilterInHasOnes(desugared.hasOneRelationPath, {
          [desugared.field]: condition
        });
        parts.push(fieldCondition);
      }
      return filter.mode === "doesNotMatch" ? { and: parts } : { or: parts };
    },
    emptyFilter: {
      mode: "matches",
      query: ""
    },
    filterRenderer: (props2) => {
      return /* @__PURE__ */ createElement(Stack, {
        direction: "horizontal"
      }, /* @__PURE__ */ createElement(GenericTextCellFilter, {
        ...props2
      }));
    }
  }, /* @__PURE__ */ createElement(CoalesceFieldView, {
    ...props
  }));
}, "CoalesceTextCell");
export { CoalesceTextCell };
//# sourceMappingURL=CoalesceTextCell.js.map
