"use strict";
const jsxRuntime = require("react/jsx-runtime");
const assert = require("assert");
const React = require("react");
const styles_lib_components_Box_Box_cjs = require("../Box/Box.cjs");
const styles_lib_components_Accordion_Accordion_cjs = require("../Accordion/Accordion.cjs");
const styles_lib_hooks_useIcon_index_cjs = require("../../hooks/useIcon/index.cjs");
const styles_lib_components_private_touchable_virtualTouchable_cjs = require("../private/touchable/virtualTouchable.cjs");
const styles_lib_components_Button_Button_cjs = require("../Button/Button.cjs");
const styles_lib_components_Accordion_AccordionItem_cjs = require("../Accordion/AccordionItem.cjs");
const styles_lib_components_TooltipRenderer_TooltipRenderer_cjs = require("../TooltipRenderer/TooltipRenderer.cjs");
const styles_lib_components_ButtonIcon_ButtonIcon_css_cjs = require("./ButtonIcon.css.cjs");
const _interopDefaultCompat = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const assert__default = /* @__PURE__ */ _interopDefaultCompat(assert);
const buttonIconVariants = ["soft", "transparent"];
const buttonIconTones = ["neutral", "secondary"];
const padding = "xsmall";
const PrivateButtonIcon = React.forwardRef(
  ({
    icon,
    label,
    id,
    size = "standard",
    tone = "neutral",
    variant = "soft",
    type = "button",
    bleed,
    tooltipPlacement,
    onClick,
    onMouseDown,
    onKeyUp,
    onKeyDown,
    "aria-haspopup": ariaHasPopUp,
    "aria-expanded": ariaExpanded,
    tabIndex,
    data,
    ...restProps
  }, forwardedRef) => {
    const {
      className: buttonClasses,
      width: _,
      ...buttonStyleProps
    } = styles_lib_components_Button_Button_cjs.useButtonStyles({
      variant,
      tone: "neutral",
      size: "standard",
      radius: "full"
    });
    assert__default.default(
      icon.props.size === void 0,
      "Icons cannot set the 'size' prop when passed to a ButtonIcon component"
    );
    const button = /* @__PURE__ */ jsxRuntime.jsxs(
      styles_lib_components_Box_Box_cjs.Box,
      {
        component: "button",
        type,
        id,
        zIndex: 0,
        title: !id ? label : void 0,
        ref: forwardedRef,
        "aria-label": label,
        "aria-haspopup": ariaHasPopUp,
        "aria-expanded": ariaExpanded,
        padding,
        onClick,
        onKeyUp,
        onKeyDown,
        onMouseDown,
        className: [buttonClasses, styles_lib_components_ButtonIcon_ButtonIcon_css_cjs.button, styles_lib_components_private_touchable_virtualTouchable_cjs.virtualTouchable()],
        tabIndex,
        ...styles_lib_components_Accordion_Accordion_cjs.buildDataAttributes({ data, validateRestProps: restProps }),
        ...buttonStyleProps,
        children: [
          /* @__PURE__ */ jsxRuntime.jsx(
            styles_lib_components_Button_Button_cjs.ButtonOverlays,
            {
              variant,
              tone: "neutral",
              radius: "full",
              keyboardFocusable: typeof tabIndex === "undefined" || tabIndex >= 0,
              forceActive: ariaExpanded === "true" || ariaExpanded === true
            }
          ),
          /* @__PURE__ */ jsxRuntime.jsx(
            styles_lib_components_Box_Box_cjs.Box,
            {
              component: "span",
              display: "block",
              position: "relative",
              className: size === "large" ? styles_lib_hooks_useIcon_index_cjs.iconContainerSize() : styles_lib_hooks_useIcon_index_cjs.iconSize({ crop: true }),
              children: React.cloneElement(icon, { tone: icon.props.tone || tone, size: "fill" })
            }
          )
        ]
      }
    );
    const shouldBleed = typeof bleed === "undefined" && variant === "transparent" || bleed;
    return shouldBleed ? /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Button_Button_cjs.Bleed, { space: padding, children: button }) : button;
  }
);
const ButtonIcon = React.forwardRef(
  ({ id, label, tooltipPlacement, ...restProps }, forwardedRef) => {
    if (!id) {
      return /* @__PURE__ */ jsxRuntime.jsx(PrivateButtonIcon, { label, ref: forwardedRef, ...restProps });
    }
    return /* @__PURE__ */ jsxRuntime.jsx(
      styles_lib_components_TooltipRenderer_TooltipRenderer_cjs.TooltipRenderer,
      {
        id: `${id}-tooltip`,
        tooltip: /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Accordion_AccordionItem_cjs.Text, { children: label }),
        placement: tooltipPlacement,
        children: ({ triggerProps: { ref: triggerRef, ...triggerProps } }) => /* @__PURE__ */ jsxRuntime.jsx(
          PrivateButtonIcon,
          {
            id,
            label,
            ref: (node) => {
              if (forwardedRef) {
                if (typeof forwardedRef === "function") {
                  forwardedRef(node);
                } else {
                  forwardedRef.current = node;
                }
              }
              triggerRef(node);
            },
            ...triggerProps,
            ...restProps
          }
        )
      }
    );
  }
);
ButtonIcon.displayName = "ButtonIcon";
exports.ButtonIcon = ButtonIcon;
exports.buttonIconTones = buttonIconTones;
exports.buttonIconVariants = buttonIconVariants;
