import { jsx } from "react/jsx-runtime";
import { Button, styled } from "@mui/material";
import apollo_core from "@uipath/apollo-core";
import { ApIcon } from "../../../index.js";
import react from "react";
import { useChatState } from "../../providers/chat-state-provider.js";
import { AutopilotChatMode } from "../../service/index.js";
import { AutopilotChatIconButton } from "./icon-button.js";
import { AutopilotChatTooltip } from "./tooltip.js";
const StyledButtonContainer = styled('div')(()=>({
        '& .MuiButton-root': {
            background: 'transparent',
            color: 'var(--color-foreground)',
            fontFamily: apollo_core.FontFamily.FontLFamily,
            fontWeight: apollo_core.FontFamily.FontWeightDefault,
            fontSize: apollo_core.FontFamily.FontSSize,
            lineHeight: apollo_core.FontFamily.FontSLineHeight,
            fontStyle: 'normal',
            minWidth: '78px',
            '&:active': {
                backgroundColor: 'transparent !important'
            },
            '&:hover, &:focus': {
                color: 'var(--color-foreground-emp)',
                backgroundColor: 'var(--color-icon-button-hover) !important'
            }
        }
    }));
const AutopilotChatActionButtonComponent = /*#__PURE__*/ react.forwardRef(({ iconName, disabled, iconSize, preventHover, overrideColor, variant = 'outlined', text, tooltip, tooltipPlacement = 'bottom', ariaLabel, ariaDescribedby, ariaPressed, title, tabIndex, onClick, onMouseEnter, onMouseLeave, onFocus, onBlur, onMouseDown, onMouseUp, onKeyDown, disableInteractiveTooltip = false, 'data-testid': dataTestId }, ref)=>{
    const [iconColor, setIconColor] = react.useState('var(--color-icon-default)');
    const { chatMode } = useChatState();
    const showTooltip = tooltip && chatMode !== AutopilotChatMode.Closed && !disabled;
    const button = text ? /*#__PURE__*/ jsx(StyledButtonContainer, {
        children: /*#__PURE__*/ jsx(Button, {
            ref: ref,
            onMouseEnter: (event)=>{
                onMouseEnter?.(event);
                if (!preventHover) setIconColor('var(--color-foreground-emp)');
            },
            onMouseLeave: (event)=>{
                onMouseLeave?.(event);
                if (!preventHover) setIconColor('var(--color-icon-default)');
            },
            startIcon: /*#__PURE__*/ jsx(ApIcon, {
                name: iconName,
                variant: variant,
                size: iconSize || apollo_core.Icon.IconS,
                color: overrideColor ?? iconColor
            }),
            "aria-label": ariaLabel,
            "aria-describedby": ariaDescribedby,
            "aria-pressed": ariaPressed,
            title: showTooltip ? void 0 : title,
            variant: "text",
            size: "small",
            disabled: disabled,
            onClick: onClick,
            onFocus: onFocus,
            onBlur: onBlur,
            onMouseDown: onMouseDown,
            onMouseUp: onMouseUp,
            tabIndex: tabIndex,
            onKeyDown: onKeyDown,
            "data-testid": dataTestId,
            children: text
        })
    }) : /*#__PURE__*/ jsx(AutopilotChatIconButton, {
        ref: ref,
        disabled: disabled,
        color: "secondary",
        onClick: onClick,
        onFocus: onFocus,
        onBlur: onBlur,
        onMouseDown: onMouseDown,
        onMouseUp: onMouseUp,
        tabIndex: tabIndex,
        onKeyDown: onKeyDown,
        "aria-label": ariaLabel,
        "aria-describedby": ariaDescribedby,
        "aria-pressed": ariaPressed,
        title: showTooltip ? void 0 : title,
        onMouseEnter: (event)=>{
            onMouseEnter?.(event);
            if (!preventHover) setIconColor('var(--color-foreground-emp)');
        },
        onMouseLeave: (event)=>{
            onMouseLeave?.(event);
            if (!preventHover) setIconColor('var(--color-icon-default)');
        },
        "data-testid": dataTestId,
        sx: 'custom' === variant ? {
            padding: '8px 6px 6px 8px'
        } : void 0,
        children: /*#__PURE__*/ jsx(ApIcon, {
            name: iconName,
            variant: variant,
            size: iconSize || ('custom' === variant ? '20px' : apollo_core.Icon.IconS),
            color: overrideColor ?? iconColor
        })
    });
    return showTooltip ? /*#__PURE__*/ jsx(AutopilotChatTooltip, {
        title: tooltip,
        placement: tooltipPlacement,
        disableInteractive: disableInteractiveTooltip,
        children: button
    }) : button;
});
const AutopilotChatActionButton = /*#__PURE__*/ react.memo(AutopilotChatActionButtonComponent);
export { AutopilotChatActionButton };
