/*
 * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import React, { useMemo, useRef } from "react";
import { SelectionCell, SelectionHeaderCell } from "../SelectionCells.js";
import { SELECTION_COLUMN_ID, SELECTION_COLUMN_WIDTH } from "../utils/constants.js";
export const useSelectionColumn = ({
  selectionMode,
  isAllSelected,
  hasSelection,
  onToggleAll,
  onToggleRow
}) => {
  // TODO: Replace with useLatestRef
  const isAllSelectedRef = useRef(isAllSelected);
  isAllSelectedRef.current = isAllSelected;
  const hasSelectionRef = useRef(hasSelection);
  hasSelectionRef.current = hasSelection;
  const onToggleAllRef = useRef(onToggleAll);
  onToggleAllRef.current = onToggleAll;
  const onToggleRowRef = useRef(onToggleRow);
  onToggleRowRef.current = onToggleRow;
  const selectionColumn = useMemo(() => {
    if (selectionMode === "none") return null;
    return {
      id: SELECTION_COLUMN_ID,
      header: () => selectionMode === "multiple" ? /*#__PURE__*/React.createElement(SelectionHeaderCell, {
        isAllSelected: isAllSelectedRef.current,
        hasSelection: hasSelectionRef.current,
        onToggleAll: onToggleAllRef.current
      }) : null,
      cell: ({
        row
      }) => /*#__PURE__*/React.createElement(SelectionCell, {
        row: row,
        onToggleRow: onToggleRowRef.current
      }),
      size: SELECTION_COLUMN_WIDTH,
      minSize: SELECTION_COLUMN_WIDTH,
      maxSize: SELECTION_COLUMN_WIDTH,
      enableSorting: false,
      enableResizing: false,
      enablePinning: false
    };
  }, [selectionMode]);
  return selectionColumn;
};
//# sourceMappingURL=useSelectionColumn.js.map