"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "ApproveButton", {
    enumerable: true,
    get: function() {
        return ApproveButton;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _button = /*#__PURE__*/ _interop_require_default(require("../../../button"));
const _toast = require("../../../toast");
const _react = require("react");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const ApproveButton = (props)=>{
    const { onApprove, onDeposit, allowance, submitting, quantity, disabled, maxQuantity, token = "USDC", label, buttonId } = props;
    const [approveLoading, setApproveLoading] = (0, _react.useState)(false);
    const onClick = (0, _react.useCallback)(()=>{
        if (approveLoading) return;
        setApproveLoading(true);
        onApprove?.().then((res)=>{
            _toast.toast.success("Approve success");
        }).catch((error)=>{
            ;
            _toast.toast.error(error?.errorCode || "Approve failed");
        }).finally(()=>{
            setApproveLoading(false);
        });
    }, [
        approveLoading,
        allowance,
        quantity,
        props.onApprove
    ]);
    if (allowance <= 0) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_button.default, {
            id: buttonId,
            fullWidth: true,
            loading: approveLoading,
            onClick: onClick,
            disabled: approveLoading,
            className: " desktop:orderly-text-2xs",
            children: `Approve ${token}`
        });
    }
    if (allowance < Number(quantity) && Number(quantity) <= Number(maxQuantity)) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_button.default, {
            id: buttonId,
            fullWidth: true,
            loading: approveLoading,
            onClick: onClick,
            disabled: approveLoading,
            className: " desktop:orderly-text-2xs",
            children: `increase ${token} authorized amount`
        });
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_button.default, {
        id: buttonId,
        fullWidth: true,
        onClick: onDeposit,
        disabled: disabled || submitting,
        loading: submitting,
        className: "desktop:orderly-text-2xs",
        children: label
    });
};

//# sourceMappingURL=approveButton.js.map