import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { Component, QueryLanguage, wrapFilterInHasOnes, Field } from "@contember/binding";
import { Stack, Select, NumberInput } from "@contember/ui";
import { dataGridCellsDictionary } from "./dataGridCellsDictionary.js";
import { NullConditionFilter } from "./NullConditionFilter.js";
import { DataGridColumn } from "../base/DataGridColumn.js";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
import { FieldFallbackView } from "../../../fieldViews/FieldFallbackView.js";
const NumberCell = 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 === null && !filter.nullCondition) {
          return void 0;
        }
        const baseOperators = {
          eq: "eq",
          gte: "gte",
          lte: "lte"
        };
        const conditions = [];
        if (filter.query !== null) {
          conditions.push({
            [baseOperators[filter.mode]]: filter.query
          });
        }
        if (filter.nullCondition) {
          conditions.push({ isNull: true });
        }
        const desugared = QueryLanguage.desugarRelativeSingleField(props, environment);
        return wrapFilterInHasOnes(desugared.hasOneRelationPath, {
          [desugared.field]: { or: conditions }
        });
      },
      emptyFilter: {
        mode: "eq",
        query: null,
        nullCondition: false
      },
      filterRenderer: ({ filter, setFilter, environment }) => {
        const formatMessage = useMessageFormatter(dataGridCellsDictionary);
        const options = [
          { value: "eq", label: formatMessage("dataGridCells.numberCell.equals") },
          { value: "gte", label: formatMessage("dataGridCells.numberCell.greaterThan") },
          { value: "lte", label: formatMessage("dataGridCells.numberCell.lessThan") }
        ];
        return /* @__PURE__ */ jsxDEV(Fragment, { children: [
          /* @__PURE__ */ jsxDEV(Stack, { direction: "horizontal", children: [
            /* @__PURE__ */ jsxDEV(
              Select,
              {
                notNull: true,
                value: filter.mode,
                options,
                onChange: (value) => {
                  if (!value) {
                    return;
                  }
                  setFilter({
                    ...filter,
                    mode: value
                  });
                }
              },
              void 0,
              false,
              {
                fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/NumberCell.tsx",
                lineNumber: 91,
                columnNumber: 8
              },
              globalThis
            ),
            /* @__PURE__ */ jsxDEV(
              NumberInput,
              {
                value: filter.query,
                placeholder: "Value",
                onChange: (value) => {
                  setFilter({
                    ...filter,
                    query: value ?? null
                  });
                }
              },
              void 0,
              false,
              {
                fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/NumberCell.tsx",
                lineNumber: 106,
                columnNumber: 8
              },
              globalThis
            )
          ] }, void 0, true, {
            fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/NumberCell.tsx",
            lineNumber: 90,
            columnNumber: 7
          }, globalThis),
          /* @__PURE__ */ jsxDEV(NullConditionFilter, { filter, setFilter, environment, field: props.field, showNullConditionFilter: props.showNullConditionFilter }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/NumberCell.tsx",
            lineNumber: 117,
            columnNumber: 7
          }, globalThis)
        ] }, void 0, true, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/NumberCell.tsx",
          lineNumber: 89,
          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/NumberCell.tsx",
                lineNumber: 126,
                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/NumberCell.tsx",
          lineNumber: 122,
          columnNumber: 4
        },
        globalThis
      )
    },
    void 0,
    false,
    {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/NumberCell.tsx",
      lineNumber: 41,
      columnNumber: 3
    },
    globalThis
  );
}, "NumberCell");
export {
  NumberCell
};
//# sourceMappingURL=NumberCell.js.map
