import { jsxDEV } from "react/jsx-dev-runtime";
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__ */ jsxDEV(
    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__ */ jsxDEV(Stack, { direction: "horizontal", children: /* @__PURE__ */ jsxDEV(GenericTextCellFilter, { ...props2 }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/CoalesceTextCell.tsx",
          lineNumber: 55,
          columnNumber: 7
        }, globalThis) }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/CoalesceTextCell.tsx",
          lineNumber: 54,
          columnNumber: 6
        }, globalThis);
      },
      children: /* @__PURE__ */ jsxDEV(CoalesceFieldView, { ...props }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/CoalesceTextCell.tsx",
        lineNumber: 60,
        columnNumber: 4
      }, globalThis)
    },
    void 0,
    false,
    {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/CoalesceTextCell.tsx",
      lineNumber: 30,
      columnNumber: 3
    },
    globalThis
  );
}, "CoalesceTextCell");
export {
  CoalesceTextCell
};
//# sourceMappingURL=CoalesceTextCell.js.map
