"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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var react_stripe_elements_1 = require("react-stripe-elements");
var react_apollo_1 = require("react-apollo");
var queries_1 = require("./queries");
var react_async_script_1 = __importDefault(require("react-async-script"));
var PaymentsStripeForm_1 = __importDefault(require("./PaymentsStripeForm"));
var context_1 = require("../context");
var __1 = require("../");
var PaymentsStripe = /** @class */ (function (_super) {
    __extends(PaymentsStripe, _super);
    function PaymentsStripe(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            stripeLoaded: false,
            stripe: null,
        };
        return _this;
    }
    PaymentsStripe.prototype.render = function () {
        var _this = this;
        var userChannelID = this.context && this.context.currentUser && this.context.currentUser.userChannel.id;
        var userEmail = this.context && this.context.currentUser && this.context.currentUser.email;
        var AsyncScriptLoader = react_async_script_1.default("https://js.stripe.com/v3/")(__1.LoadingMessage);
        if (this.state.stripeLoaded) {
            return (React.createElement(react_stripe_elements_1.StripeProvider, { apiKey: this.context.config.STRIPE_API_KEY },
                React.createElement(react_stripe_elements_1.Elements, null,
                    React.createElement(react_apollo_1.Mutation, { mutation: queries_1.PAYMENTS_STRIPE_MUTATION }, function (paymentsCreateStripePayment) {
                        return (React.createElement(PaymentsStripeForm_1.default, { postId: _this.props.postId, newsroomName: _this.props.newsroomName, shouldPublicize: _this.props.shouldPublicize, userEmail: userEmail, userChannelID: userChannelID, usdToSpend: _this.props.usdToSpend, savePayment: paymentsCreateStripePayment, handlePaymentSuccess: _this.props.handlePaymentSuccess, handleEditPaymentType: _this.props.handleEditPaymentType }));
                    }))));
        }
        return (React.createElement(AsyncScriptLoader, { asyncScriptOnLoad: function () {
                _this.setState({ stripeLoaded: true });
            } }));
    };
    PaymentsStripe.contextType = context_1.CivilContext;
    return PaymentsStripe;
}(React.Component));
exports.PaymentsStripe = PaymentsStripe;
//# sourceMappingURL=PaymentsStripe.js.map