import { createElement, Fragment, useCallback } from "react";
import { Select, TextInput } from "@contember/ui";
import { dataGridCellsDictionary } from "./dataGridCellsDictionary.js";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
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__ */ createElement(Fragment, null, /* @__PURE__ */ createElement(Select, {
    required: true,
    options,
    onChange: (value) => {
      setFilter({
        ...filter,
        mode: value
      });
    },
    placeholder: null,
    value: filter.mode
  }), /* @__PURE__ */ createElement(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])
  }));
};
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
