import { jsxDEV } from "react/jsx-dev-runtime";
import { Component, QueryLanguage, wrapFilterInHasOnes } from "@contember/binding";
import { Stack, FieldContainer, Checkbox } from "@contember/ui";
import { dataGridCellsDictionary } from "./dataGridCellsDictionary.js";
import { BooleanFieldView } from "../../../fieldViews/BooleanFieldView.js";
import { DataGridColumn } from "../base/DataGridColumn.js";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
const BooleanCell = Component((props) => {
  return /* @__PURE__ */ jsxDEV(
    DataGridColumn,
    {
      shrunk: true,
      ...props,
      enableOrdering: !props.disableOrder,
      getNewOrderBy: (newDirection, { environment }) => newDirection ? QueryLanguage.desugarOrderBy(`${props.field} ${newDirection}`, environment) : void 0,
      getNewFilter: (filterArtifact, { environment }) => {
        const conditions = [];
        if (filterArtifact.includeTrue) {
          conditions.push({ eq: true });
        }
        if (filterArtifact.includeFalse) {
          conditions.push({ eq: false });
        }
        if (filterArtifact.includeNull) {
          conditions.push({ isNull: true });
        }
        if (conditions.length === 0 || conditions.length === 3) {
          return void 0;
        }
        const desugared = QueryLanguage.desugarRelativeSingleField(props.field, environment);
        return wrapFilterInHasOnes(desugared.hasOneRelationPath, {
          [desugared.field]: conditions.length > 1 ? { or: conditions } : conditions[0]
        });
      },
      emptyFilter: {
        includeFalse: false,
        includeTrue: false,
        includeNull: false
      },
      filterRenderer: ({ filter, setFilter }) => {
        const formatMessage = useMessageFormatter(dataGridCellsDictionary);
        return /* @__PURE__ */ jsxDEV(Stack, { direction: "horizontal", children: [
          ["includeTrue", formatMessage("dataGridCells.booleanCell.includeTrue")],
          ["includeFalse", formatMessage("dataGridCells.booleanCell.includeFalse")],
          ["includeNull", formatMessage("dataGridCells.booleanCell.includeNull")]
        ].map(([item, label], index) => /* @__PURE__ */ jsxDEV(
          FieldContainer,
          {
            label,
            labelPosition: "labelInlineRight",
            children: /* @__PURE__ */ jsxDEV(
              Checkbox,
              {
                notNull: true,
                value: filter[item],
                onChange: (checked) => {
                  setFilter({ ...filter, [item]: checked });
                }
              },
              item,
              false,
              {
                fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/BooleanCell.tsx",
                lineNumber: 86,
                columnNumber: 9
              },
              globalThis
            )
          },
          `${index}-${label}`,
          false,
          {
            fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/BooleanCell.tsx",
            lineNumber: 81,
            columnNumber: 8
          },
          globalThis
        )) }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/BooleanCell.tsx",
          lineNumber: 73,
          columnNumber: 6
        }, globalThis);
      },
      children: /* @__PURE__ */ jsxDEV(BooleanFieldView, { ...props }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/BooleanCell.tsx",
        lineNumber: 100,
        columnNumber: 4
      }, globalThis)
    },
    void 0,
    false,
    {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/BooleanCell.tsx",
      lineNumber: 37,
      columnNumber: 3
    },
    globalThis
  );
}, "BooleanCell");
export {
  BooleanCell
};
//# sourceMappingURL=BooleanCell.js.map
