/*
 * Copyright 2026 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 { Button } from "@base-ui/react/button";
import { Tooltip } from "@base-ui/react/tooltip";
import classnames from "classnames";
import React from "react";
import { getDisplayLabel, isDisallowed } from "./selectionStateHelpers.js";
import styles from "./MarkingButton.module.css";
const selectionStateClassMap = {
  SELECTED: styles.selected,
  IMPLIED: styles.implied,
  DISALLOWED: styles.disallowed,
  IMPLIED_DISALLOWED: styles.impliedDisallowed,
  NONE: undefined
};
function getSelectionHint(state) {
  switch (state) {
    case "SELECTED":
      return "Click to deselect";
    case "IMPLIED":
      return "Implied by another marking";
    case "DISALLOWED":
    case "IMPLIED_DISALLOWED":
      return "Not available with current selection. Deselect your current choice first.";
    case "NONE":
      return undefined;
  }
}
export const MarkingButton = /*#__PURE__*/React.memo(function ({
  id,
  label,
  description,
  selectionState,
  onToggle,
  disabled
}) {
  const handleToggle = React.useCallback(() => {
    onToggle(id);
  }, [onToggle, id]);
  const hasDescription = description !== undefined && description.length > 0;
  const isButtonDisabled = disabled ?? isDisallowed(selectionState);
  const showTooltip = hasDescription || isDisallowed(selectionState);
  const hint = getSelectionHint(selectionState);
  const button = /*#__PURE__*/React.createElement(Button, {
    className: classnames(styles.markingButton, selectionStateClassMap[selectionState]),
    onClick: isButtonDisabled ? undefined : handleToggle,
    disabled: showTooltip ? undefined : isButtonDisabled,
    "aria-disabled": showTooltip ? isButtonDisabled : undefined,
    "aria-pressed": selectionState === "SELECTED" || selectionState === "IMPLIED",
    title: showTooltip ? undefined : label
  }, getDisplayLabel(label, selectionState));
  if (!showTooltip) {
    return button;
  }
  return /*#__PURE__*/React.createElement(Tooltip.Root, null, /*#__PURE__*/React.createElement(Tooltip.Trigger, {
    render: button
  }), /*#__PURE__*/React.createElement(Tooltip.Portal, null, /*#__PURE__*/React.createElement(Tooltip.Positioner, {
    sideOffset: 8
  }, /*#__PURE__*/React.createElement(Tooltip.Popup, {
    className: styles.tooltip
  }, /*#__PURE__*/React.createElement("p", {
    className: styles.tooltipTitle
  }, label), hasDescription && /*#__PURE__*/React.createElement("p", {
    className: styles.tooltipDescription
  }, description), hint != null && /*#__PURE__*/React.createElement("p", {
    className: styles.tooltipHint
  }, hint)))));
});
//# sourceMappingURL=MarkingButton.js.map