import { FieldContainer, Checkbox } from "@contember/ui";
import { useMemo } from "react";
import { useSelectOptions } from "../../../fields/ChoiceField/hooks/useSelectOptions.js";
import { dataGridCellsDictionary } from "./dataGridCellsDictionary.js";
import { useCurrentlyChosenEntities } from "../../../fields/ChoiceField/hooks/useCurrentlyChosenEntities.js";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { MultiSelectFieldInner } from "../../../fields/SelectField/MultiSelectField.js";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/SelectCellFilter.tsx";
const SelectCellFilter = ({
  filter,
  setFilter,
  optionProps
}) => {
  const currentlyChosenEntities = useCurrentlyChosenEntities(optionProps, filter.id);
  const {
    options,
    allOptions,
    onSearch,
    isLoading
  } = useSelectOptions(optionProps, currentlyChosenEntities);
  const currentValues = useMemo(() => {
    return allOptions.filter((it) => filter.id.includes(it.value.id));
  }, [filter.id, allOptions]);
  const formatMessage = useMessageFormatter(dataGridCellsDictionary);
  return /* @__PURE__ */ jsxDEV(Fragment, {
    children: [/* @__PURE__ */ jsxDEV(MultiSelectFieldInner, {
      label: void 0,
      data: options,
      onAdd: (val) => setFilter({
        ...filter,
        id: [...filter.id, val.value.id]
      }),
      onRemove: (val) => setFilter({
        ...filter,
        id: filter.id.filter((it) => it !== val.value.id)
      }),
      errors: void 0,
      currentValues,
      onClear: () => {
        setFilter({
          ...filter,
          id: []
        });
      },
      onSearch,
      isLoading
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 31,
      columnNumber: 3
    }, void 0), /* @__PURE__ */ jsxDEV(FieldContainer, {
      label: /* @__PURE__ */ jsxDEV("span", {
        style: {
          whiteSpace: "nowrap"
        },
        children: formatMessage("dataGridCells.textCell.includeNull", {
          strong: (chunks) => /* @__PURE__ */ jsxDEV("strong", {
            children: chunks
          }, void 0, false, {
            fileName: _jsxFileName,
            lineNumber: 48,
            columnNumber: 24
          }, void 0)
        })
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 46,
        columnNumber: 11
      }, void 0),
      labelPosition: "labelInlineRight",
      children: /* @__PURE__ */ jsxDEV(Checkbox, {
        notNull: true,
        value: filter.nullCondition,
        onChange: (checked) => {
          setFilter({
            ...filter,
            nullCondition: !!checked
          });
        }
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 53,
        columnNumber: 4
      }, void 0)
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 45,
      columnNumber: 3
    }, void 0)]
  }, void 0, true);
};
export {
  SelectCellFilter
};
//# sourceMappingURL=SelectCellFilter.js.map
