import { jsxDEV } from "react/jsx-dev-runtime";
import { Component, QueryLanguage, wrapFilterInHasOnes, Field } from "@contember/binding";
import { Stack, FieldContainer, Checkbox } from "@contember/ui";
import { dataGridCellsDictionary } from "./dataGridCellsDictionary.js";
import { createGenericTextCellFilterCondition, GenericTextCellFilter } from "./GenericTextCellFilter.js";
import { DataGridColumn } from "../base/DataGridColumn.js";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
import { FieldFallbackView } from "../../../fieldViews/FieldFallbackView.js";
const TextCell = Component((props) => {
  return /* @__PURE__ */ jsxDEV(
    DataGridColumn,
    {
      ...props,
      enableOrdering: !props.disableOrder,
      getNewOrderBy: (newDirection, { environment }) => newDirection ? QueryLanguage.desugarOrderBy(`${props.field} ${newDirection}`, environment) : void 0,
      getNewFilter: (filter, { environment }) => {
        if (filter.query === "" && filter.nullCondition === false) {
          return void 0;
        }
        let condition = filter.query !== "" ? createGenericTextCellFilterCondition(filter) : {};
        if (filter.mode === "doesNotMatch") {
          if (filter.nullCondition) {
            condition = {
              and: [condition, { isNull: false }]
            };
          }
        } else if (filter.nullCondition) {
          condition = {
            or: [condition, { isNull: true }]
          };
        }
        const desugared = QueryLanguage.desugarRelativeSingleField(props, environment);
        return wrapFilterInHasOnes(desugared.hasOneRelationPath, {
          [desugared.field]: condition
        });
      },
      emptyFilter: {
        mode: "matches",
        query: "",
        nullCondition: false
      },
      filterRenderer: ({ filter, setFilter, ...props2 }) => {
        const formatMessage = useMessageFormatter(dataGridCellsDictionary);
        return /* @__PURE__ */ jsxDEV(Stack, { direction: "horizontal", children: [
          /* @__PURE__ */ jsxDEV(GenericTextCellFilter, { ...props2, filter, setFilter }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
            lineNumber: 84,
            columnNumber: 7
          }, globalThis),
          /* @__PURE__ */ jsxDEV(
            FieldContainer,
            {
              label: /* @__PURE__ */ jsxDEV("span", { style: { whiteSpace: "nowrap" }, children: filter.mode === "doesNotMatch" ? formatMessage("dataGridCells.textCell.excludeNull", {
                strong: (chunks) => /* @__PURE__ */ jsxDEV("strong", { children: chunks }, void 0, false, {
                  fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
                  lineNumber: 89,
                  columnNumber: 31
                }, globalThis)
              }) : formatMessage("dataGridCells.textCell.includeNull", {
                strong: (chunks) => /* @__PURE__ */ jsxDEV("strong", { children: chunks }, void 0, false, {
                  fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
                  lineNumber: 92,
                  columnNumber: 31
                }, globalThis)
              }) }, void 0, false, {
                fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
                lineNumber: 86,
                columnNumber: 16
              }, globalThis),
              labelPosition: "labelInlineRight",
              children: /* @__PURE__ */ jsxDEV(
                Checkbox,
                {
                  notNull: true,
                  value: filter.nullCondition,
                  onChange: (checked) => {
                    setFilter({
                      ...filter,
                      nullCondition: !!checked
                    });
                  }
                },
                void 0,
                false,
                {
                  fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
                  lineNumber: 97,
                  columnNumber: 9
                },
                globalThis
              )
            },
            void 0,
            false,
            {
              fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
              lineNumber: 85,
              columnNumber: 8
            },
            globalThis
          )
        ] }, void 0, true, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
          lineNumber: 83,
          columnNumber: 6
        }, globalThis);
      },
      children: /* @__PURE__ */ jsxDEV(
        Field,
        {
          ...props,
          format: (value) => {
            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/collections/DataGrid/cells/TextCell.tsx",
                lineNumber: 116,
                columnNumber: 14
              }, globalThis);
            }
            if (props.format) {
              return props.format(value);
            }
            return value;
          }
        },
        void 0,
        false,
        {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
          lineNumber: 112,
          columnNumber: 4
        },
        globalThis
      )
    },
    void 0,
    false,
    {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/TextCell.tsx",
      lineNumber: 45,
      columnNumber: 3
    },
    globalThis
  );
}, "TextCell");
export {
  TextCell
};
//# sourceMappingURL=TextCell.js.map
