"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var ramp_instant_sdk_1 = require("@ramp-network/ramp-instant-sdk");
var react_1 = require("react");
var react_use_mutable_1 = require("react-use-mutable");
exports.Ramp = function (_a) {
    var address = _a.address, amount = _a.amount, currency = _a.currency, config = _a.config, onSuccess = _a.onSuccess, onCancel = _a.onCancel;
    var _b = __read(react_1.useState(false), 2), purchaseCreated = _b[0], setPurchaseCreated = _b[1];
    var onClose = react_use_mutable_1.useMutableCallback(purchaseCreated ? onSuccess : onCancel);
    react_1.useEffect(function () {
        var ramp = new ramp_instant_sdk_1.RampInstantSDK({
            hostAppName: config.appName,
            hostLogoUrl: config.logoUrl,
            swapAmount: amount,
            swapAsset: currency,
            url: config.rampUrl,
            userAddress: address,
            variant: 'auto',
        }).on(ramp_instant_sdk_1.RampInstantEventTypes.PURCHASE_CREATED, function () { return setPurchaseCreated(true); })
            .on(ramp_instant_sdk_1.RampInstantEventTypes.WIDGET_CLOSE, onClose);
        ramp.domNodes.overlay.style.zIndex = '99999';
        ramp.show();
    }, []);
    return null;
};
//# sourceMappingURL=Ramp.js.map