import { Component, QueryLanguage, wrapFilterInHasOnes } from "@contember/binding";
import { Stack, FieldContainer, Checkbox } from "@contember/ui";
import { dataGridCellsDictionary } from "./dataGridCellsDictionary.js";
import { jsxDEV } from "react/jsx-dev-runtime";
import { BooleanFieldView } from "../../../fieldViews/BooleanFieldView.js";
import { DataGridColumn } from "../base/DataGridColumn.js";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/BooleanCell.tsx";
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: _jsxFileName,
            lineNumber: 75,
            columnNumber: 9
          }, void 0)
        }, `${index}-${label}`, false, {
          fileName: _jsxFileName,
          lineNumber: 70,
          columnNumber: 8
        }, void 0))
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 62,
        columnNumber: 6
      }, void 0);
    },
    children: /* @__PURE__ */ jsxDEV(BooleanFieldView, {
      ...props
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 89,
      columnNumber: 4
    }, void 0)
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 26,
    columnNumber: 3
  }, void 0);
}, "BooleanCell");
export {
  BooleanCell
};
//# sourceMappingURL=BooleanCell.js.map
