import { Select, TextInput } from "@contember/ui";
import { useCallback } from "react";
import { dataGridCellsDictionary } from "./dataGridCellsDictionary.js";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/GenericTextCellFilter.tsx";
const GenericTextCellFilter = ({
  filter,
  setFilter
}) => {
  const formatMessage = useMessageFormatter(dataGridCellsDictionary);
  const options = [{
    value: "matches",
    label: formatMessage("dataGridCells.textCell.matches")
  }, {
    value: "doesNotMatch",
    label: formatMessage("dataGridCells.textCell.doesNotMatch")
  }, {
    value: "matchesExactly",
    label: formatMessage("dataGridCells.textCell.matchesExactly")
  }, {
    value: "startsWith",
    label: formatMessage("dataGridCells.textCell.startsWith")
  }, {
    value: "endsWith",
    label: formatMessage("dataGridCells.textCell.endsWith")
  }];
  return /* @__PURE__ */ jsxDEV(Fragment, {
    children: [/* @__PURE__ */ jsxDEV(Select, {
      required: true,
      options,
      onChange: (value) => {
        setFilter({
          ...filter,
          mode: value
        });
      },
      placeholder: null,
      value: filter.mode
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 31,
      columnNumber: 4
    }, void 0), /* @__PURE__ */ jsxDEV(TextInput, {
      notNull: true,
      value: filter.query,
      placeholder: formatMessage("dataGridCells.textCell.queryPlaceholder"),
      onChange: useCallback((value) => {
        if (value === null || value === void 0) {
          throw new Error("should not happen");
        }
        setFilter({
          ...filter,
          query: value
        });
      }, [filter, setFilter])
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 43,
      columnNumber: 4
    }, void 0)]
  }, void 0, true);
};
const createGenericTextCellFilterCondition = (filter) => {
  const baseOperators = {
    matches: "containsCI",
    doesNotMatch: "containsCI",
    startsWith: "startsWithCI",
    endsWith: "endsWithCI",
    matchesExactly: "eq"
  };
  let condition = {
    [baseOperators[filter.mode]]: filter.query
  };
  if (filter.mode === "doesNotMatch") {
    condition = {
      not: condition
    };
  }
  return condition;
};
export {
  GenericTextCellFilter,
  createGenericTextCellFilterCondition
};
//# sourceMappingURL=GenericTextCellFilter.js.map
