import { jsx } from 'react/jsx-runtime';
import { forwardRef, useMemo, useCallback } from 'react';
import { V as VirtualizedOptionsPanel, O as OptionsPanel } from './syncFilterUtils-BLcRXQfd.js';

const MultiSelectOptions = forwardRef(({ selectedOptions, items, virtualize, ...rest }, ref) => {
  const selectedIds = useMemo(
    () => new Set(selectedOptions.map((opt) => opt.id)),
    [selectedOptions]
  );
  const getCheckedState = useCallback(
    (item) => {
      if (item.type === "select-all" || item.type === "select-filtered") {
        return item.checkState ?? "indeterminate";
      }
      const checkId = item.type === "pinned-option" ? item.original.id : item.id;
      return selectedIds.has(checkId) ? "checked" : "unchecked";
    },
    [selectedIds]
  );
  const ListComponent = virtualize ? VirtualizedOptionsPanel : OptionsPanel;
  return /* @__PURE__ */ jsx(
    ListComponent,
    {
      ...rest,
      ref,
      items,
      selectionType: "multiple",
      getCheckedState
    }
  );
});
MultiSelectOptions.displayName = "MultiSelectOptions";

const useToggleSelection = ({
  options,
  pinnedSections,
  selectedOptions,
  onSelectedOptionsChange
}) => {
  const allPinnedOptions = useMemo(() => {
    return pinnedSections.flatMap((section) => section.options);
  }, [pinnedSections]);
  const handleItemClick = useCallback(
    (option) => {
      const isSelected = selectedOptions.some((opt) => opt.id === option.id);
      if (isSelected) {
        onSelectedOptionsChange(
          selectedOptions.filter((opt) => opt.id !== option.id)
        );
      } else {
        const fullOption = options.find((opt) => opt.id === option.id) || allPinnedOptions.find((opt) => opt.id === option.id);
        if (fullOption) {
          onSelectedOptionsChange([...selectedOptions, fullOption]);
        }
      }
    },
    [selectedOptions, onSelectedOptionsChange, options, allPinnedOptions]
  );
  return { handleItemClick, allPinnedOptions };
};

export { MultiSelectOptions as M, useToggleSelection as u };
//# sourceMappingURL=useToggleSelection-D_2qS0P1.js.map
