import { jsx as _jsx } from "react/jsx-runtime";
import Button from "../../../button";
import { toast } from "../../../toast";
import { useCallback, useState } from "react";
export const ApproveButton = (props)=>{
    const { onApprove, onDeposit, allowance, submitting, quantity, disabled, maxQuantity, token = "USDC", label, buttonId } = props;
    const [approveLoading, setApproveLoading] = useState(false);
    const onClick = useCallback(()=>{
        if (approveLoading) return;
        setApproveLoading(true);
        onApprove?.().then((res)=>{
            toast.success("Approve success");
        }).catch((error)=>{
            ;
            toast.error(error?.errorCode || "Approve failed");
        }).finally(()=>{
            setApproveLoading(false);
        });
    }, [
        approveLoading,
        allowance,
        quantity,
        props.onApprove
    ]);
    if (allowance <= 0) {
        return /*#__PURE__*/ _jsx(Button, {
            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__*/ _jsx(Button, {
            id: buttonId,
            fullWidth: true,
            loading: approveLoading,
            onClick: onClick,
            disabled: approveLoading,
            className: " desktop:orderly-text-2xs",
            children: `increase ${token} authorized amount`
        });
    }
    return /*#__PURE__*/ _jsx(Button, {
        id: buttonId,
        fullWidth: true,
        onClick: onDeposit,
        disabled: disabled || submitting,
        loading: submitting,
        className: "desktop:orderly-text-2xs",
        children: label
    });
};

//# sourceMappingURL=approveButton.js.map