/*
 * 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, { useCallback } from "react";
import { Checkbox } from "../base-components/checkbox/Checkbox.js";
import { useObjectTableLabels } from "./ObjectTableLabels.js";
export function SelectionHeaderCell({
  isAllSelected,
  hasSelection,
  onToggleAll
}) {
  const labels = useObjectTableLabels();
  const checkboxLabel = hasSelection ? labels.deselectAllRows : labels.selectAllRows;
  return /*#__PURE__*/React.createElement(Checkbox, {
    indeterminate: hasSelection && !isAllSelected,
    checked: isAllSelected,
    onCheckedChange: onToggleAll,
    "aria-label": checkboxLabel
  });
}
export function SelectionCell({
  row,
  onToggleRow
}) {
  const labels = useObjectTableLabels();
  const handleClick = useCallback(event => {
    // TODO: Create ActionBoundary component
    event.stopPropagation();
    const isShiftClick = event.shiftKey;
    onToggleRow(row.id, row.index, isShiftClick);
  }, [onToggleRow, row.id, row.index]);
  const handleKeyDown = useCallback(event => {
    // TODO: support shift + space
    // It looks like when we handle shift key here, the checkbox gets toggled twice
    if (event.key === "Enter") {
      const isShiftClick = event.shiftKey;
      onToggleRow(row.id, row.index, isShiftClick);
    }
  }, [onToggleRow, row.id, row.index]);
  return /*#__PURE__*/React.createElement("div", {
    onClick: handleClick,
    onKeyDown: handleKeyDown
  }, /*#__PURE__*/React.createElement(Checkbox, {
    checked: row.getIsSelected(),
    "aria-label": labels.selectRow(row.index + 1)
  }));
}
//# sourceMappingURL=SelectionCells.js.map