import { jsx as _jsx } from "react/jsx-runtime";
import { useCallback } from 'react';
import { ArrowUp, CircleStop } from '@gravity-ui/icons';
import { Icon, Spin } from '@gravity-ui/uikit';
import { block } from "../../../utils/cn.js";
import { ActionButton } from "../ActionButton/index.js";
import { i18n } from "./i18n/index.js";
import "./SubmitButton.css";
const b = block('submit-button');
/**
 * Submit button component with state management through props
 *
 * States:
 * - disabled: disabled button state
 * - enabled: enabled button state
 * - loading: loading state
 * - cancelable: cancellation state (during loading)
 *
 * @returns Submit button component
 */
export function SubmitButton({ onClick, state, className, size = 'm', tooltipSend, tooltipCancel, cancelableText, qa, }) {
    const isCancelable = state === 'cancelable';
    const isLoading = state === 'loading';
    const isDisabled = state === 'disabled';
    const handleClick = useCallback(async () => {
        if (['enabled', 'cancelable'].includes(state)) {
            return onClick();
        }
        return Promise.resolve();
    }, [state, onClick]);
    // Get tooltip based on state
    const getTooltipTitle = () => {
        switch (state) {
            case 'enabled':
                return tooltipSend || i18n('tooltip-send');
            case 'cancelable':
                return tooltipCancel || i18n('tooltip-cancel');
            case 'disabled':
            case 'loading':
                return undefined;
            default:
                return undefined;
        }
    };
    const renderContent = () => {
        if (isLoading) {
            return (_jsx("div", { className: b('loader'), children: _jsx(Spin, { className: b('spinner'), size: "xs" }) }));
        }
        if (isCancelable) {
            return cancelableText ? ([_jsx(Icon, { size: 16, data: CircleStop }, "icon"), cancelableText]) : (_jsx(Icon, { size: 16, data: CircleStop }));
        }
        return _jsx(Icon, { size: 16, data: ArrowUp });
    };
    return (_jsx(ActionButton, { view: "action", size: size, color: "brand", disabled: isDisabled, onClick: handleClick, className: b({ size, loading: isLoading, cancelable: isCancelable }, className), qa: qa, tooltipTitle: getTooltipTitle(), children: renderContent() }));
}
//# sourceMappingURL=SubmitButton.js.map
