"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var PaymentsOptions_1 = require("./PaymentsOptions");
var PaymentsEth_1 = require("./PaymentsEth");
var PaymentsStripe_1 = require("./PaymentsStripe");
var PaymentsWrapper_1 = require("./PaymentsWrapper");
var PaymentsAmount_1 = require("./PaymentsAmount");
var PaymentsLoginOrGuest_1 = require("./PaymentsLoginOrGuest");
var types_1 = require("./types");
var PaymentsTextComponents_1 = require("./PaymentsTextComponents");
var Payments = /** @class */ (function (_super) {
    __extends(Payments, _super);
    function Payments(props) {
        var _this = _super.call(this, props) || this;
        _this.handleUpdateState = function (paymentState) {
            if (paymentState === types_1.PAYMENT_STATE.STRIPE_PAYMENT && _this.state.usdToSpend < 2) {
                _this.setState({ paymentState: paymentState, usdToSpend: 2 });
            }
            else {
                _this.setState({ paymentState: paymentState });
            }
        };
        _this.handleAmount = function (usdToSpend, shouldPublicize) {
            if (_this.props.isLoggedIn) {
                _this.setState({ usdToSpend: usdToSpend, paymentState: types_1.PAYMENT_STATE.SELECT_PAYMENT_TYPE, shouldPublicize: shouldPublicize });
            }
            else {
                _this.setState({ usdToSpend: usdToSpend, paymentState: types_1.PAYMENT_STATE.PAYMENT_CHOOSE_LOGIN_OR_GUEST, shouldPublicize: shouldPublicize });
            }
        };
        _this.state = {
            usdToSpend: 0,
            shouldPublicize: false,
            paymentState: types_1.PAYMENT_STATE.SELECT_AMOUNT,
        };
        return _this;
    }
    Payments.prototype.render = function () {
        var _a = this.state, usdToSpend = _a.usdToSpend, shouldPublicize = _a.shouldPublicize, paymentState = _a.paymentState;
        var _b = this.props, postId = _b.postId, paymentAddress = _b.paymentAddress, newsroomName = _b.newsroomName, isStripeConnected = _b.isStripeConnected, userAddress = _b.userAddress, userEmail = _b.userEmail;
        var isWalletConnected = userAddress ? true : false;
        if (paymentState === types_1.PAYMENT_STATE.PAYMENT_CHOOSE_LOGIN_OR_GUEST) {
            return React.createElement(PaymentsLoginOrGuest_1.PaymentsLoginOrGuest, { handleNext: this.handleUpdateState, handleLogin: this.props.handleLogin });
        }
        if (paymentState === types_1.PAYMENT_STATE.SELECT_PAYMENT_TYPE) {
            return (React.createElement(PaymentsWrapper_1.PaymentsWrapper, { usdToSpend: usdToSpend, newsroomName: newsroomName },
                React.createElement(PaymentsOptions_1.PaymentsOptions, { usdToSpend: usdToSpend, isStripeConnected: isStripeConnected, handleNext: this.handleUpdateState })));
        }
        if (paymentState === types_1.PAYMENT_STATE.ETH_PAYMENT) {
            return (React.createElement(PaymentsWrapper_1.PaymentsWrapper, { usdToSpend: usdToSpend, newsroomName: newsroomName },
                React.createElement(PaymentsEth_1.PaymentsEth, { postId: postId, newsroomName: newsroomName, paymentAddress: paymentAddress, shouldPublicize: shouldPublicize, userAddress: userAddress, userEmail: userEmail, usdToSpend: usdToSpend, isWalletConnected: isWalletConnected, handlePaymentSuccess: this.handleUpdateState })));
        }
        if (paymentState === types_1.PAYMENT_STATE.STRIPE_PAYMENT) {
            return (React.createElement(PaymentsWrapper_1.PaymentsWrapper, { usdToSpend: usdToSpend, newsroomName: newsroomName },
                React.createElement(PaymentsStripe_1.PaymentsStripe, { postId: postId, newsroomName: newsroomName, shouldPublicize: shouldPublicize, userEmail: userEmail, usdToSpend: usdToSpend, handlePaymentSuccess: this.handleUpdateState })));
        }
        if (paymentState === types_1.PAYMENT_STATE.PAYMENT_SUCCESS) {
            return React.createElement(PaymentsTextComponents_1.PaymentSuccessText, { newsroomName: this.props.newsroomName, usdToSpend: this.state.usdToSpend });
        }
        return (React.createElement(PaymentsWrapper_1.PaymentsWrapper, { newsroomName: newsroomName },
            React.createElement(PaymentsAmount_1.PaymentsAmount, { newsroomName: newsroomName, suggestedAmounts: types_1.SuggestedPaymentAmounts, handleAmount: this.handleAmount })));
    };
    return Payments;
}(React.Component));
exports.Payments = Payments;
//# sourceMappingURL=Payments.js.map