import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
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 { MultiSelectFieldInner } from "../../../fields/SelectField/MultiSelectField.js";
import { useMessageFormatter } from "../../../../../i18n/useMessageFormatter.js";
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: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/SelectCellFilter.tsx",
        lineNumber: 37,
        columnNumber: 3
      },
      globalThis
    ),
    /* @__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: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/SelectCellFilter.tsx",
            lineNumber: 54,
            columnNumber: 24
          }, globalThis)
        }) }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/SelectCellFilter.tsx",
          lineNumber: 52,
          columnNumber: 11
        }, globalThis),
        labelPosition: "labelInlineRight",
        children: /* @__PURE__ */ jsxDEV(
          Checkbox,
          {
            notNull: true,
            value: filter.nullCondition,
            onChange: (checked) => {
              setFilter({
                ...filter,
                nullCondition: !!checked
              });
            }
          },
          void 0,
          false,
          {
            fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/SelectCellFilter.tsx",
            lineNumber: 59,
            columnNumber: 4
          },
          globalThis
        )
      },
      void 0,
      false,
      {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/SelectCellFilter.tsx",
        lineNumber: 51,
        columnNumber: 3
      },
      globalThis
    )
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/cells/SelectCellFilter.tsx",
    lineNumber: 36,
    columnNumber: 9
  }, globalThis);
};
export {
  SelectCellFilter
};
//# sourceMappingURL=SelectCellFilter.js.map
