import { LoadingOutlined } from "@ant-design/icons";
import { TextOptimize } from "@sofa-design/icons";
import { ConfigProvider, Tooltip } from "antd";
import React, { useContext } from "react";
import { useLocale } from "../../I18n";
import { ErrorBoundary } from "react-error-boundary";
import { ActionIconBox } from "../../Components/ActionIconBox";
import { isBrowserEnv } from "./env";
import { useStyle } from "./style";
export var RefinePromptButton = function RefinePromptButton(props) {
    var disabled = props.disabled, status = props.status, onRefine = props.onRefine;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var locale = useLocale();
    var baseCls = getPrefixCls('agentic-md-input-field-refine-button');
    var wrapSSR = useStyle(baseCls).wrapSSR;
    var handleClick = function handleClick() {
        if (disabled) return;
        if (status === 'loading') return;
        onRefine();
    };
    var renderIcon = function renderIcon() {
        if (status === 'loading') return /*#__PURE__*/ React.createElement(LoadingOutlined, null);
        return /*#__PURE__*/ React.createElement(TextOptimize, null);
    };
    if (!isBrowserEnv()) {
        return null;
    }
    return wrapSSR(/*#__PURE__*/ React.createElement(Tooltip, {
        title: status === 'loading' ? locale['refine.loading'] : locale['refine.oneClickOptimize']
    }, /*#__PURE__*/ React.createElement(ActionIconBox, {
        title: locale['refine.optimizePrompt'],
        onClick: handleClick,
        "data-testid": "refine-prompt-button"
    }, /*#__PURE__*/ React.createElement(ErrorBoundary, {
        fallback: /*#__PURE__*/ React.createElement("div", null)
    }, renderIcon()))));
};
