"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 TokensStyledComponents_1 = require("./TokensStyledComponents");
var TokensTextComponents_1 = require("./TokensTextComponents");
var TokensAccountSignup_1 = require("./TokensAccountSignup");
var TokensAccountVerify_1 = require("./TokensAccountVerify");
var TokensAccountBuy_1 = require("./TokensAccountBuy");
var TokensAccountHelp_1 = require("./TokensAccountHelp");
var TokensAccountProgress_1 = require("./TokensAccountProgress");
var TokensAccountFaq_1 = require("./TokensAccountFaq");
var utils_1 = require("@joincivil/utils");
var TokensAccountPaypal_1 = require("./TokensAccountPaypal");
var BrowserCompatible_1 = require("../BrowserCompatible");
var TOKEN_PROGRESS;
(function (TOKEN_PROGRESS) {
    TOKEN_PROGRESS["ACTIVE"] = "active";
    TOKEN_PROGRESS["COMPLETED"] = "completed";
    TOKEN_PROGRESS["DISABLED"] = "disabled";
})(TOKEN_PROGRESS = exports.TOKEN_PROGRESS || (exports.TOKEN_PROGRESS = {}));
var UserTokenAccount = /** @class */ (function (_super) {
    __extends(UserTokenAccount, _super);
    function UserTokenAccount(props) {
        var _this = _super.call(this, props) || this;
        _this.renderBrowserIncompatible = function () {
            return (React.createElement(TokensStyledComponents_1.FlexColumnsPrimaryModule, null,
                React.createElement(BrowserCompatible_1.BrowserCompatible, null)));
        };
        _this.renderTokenSteps = function (loggedInState, tutorialState, buyState) {
            return (React.createElement(React.Fragment, null,
                React.createElement(TokensAccountSignup_1.UserTokenAccountSignup, { user: _this.props.user, step: loggedInState, addWalletPath: _this.props.addWalletPath, signupPath: _this.props.signupPath }),
                React.createElement(TokensAccountVerify_1.UserTokenAccountVerify, { step: tutorialState, open: _this.state.isTutorialModalOpen, handleClose: function () { return _this.closeTutorialModal(_this.props.user); }, handleOpen: _this.openTutorialModal }),
                React.createElement(TokensAccountBuy_1.UserTokenAccountBuy, { step: buyState, network: _this.props.network, foundationAddress: _this.props.foundationAddress })));
        };
        _this.getAccountComplete = function (user) {
            if (user && user.ethAddress) {
                return true;
            }
            return false;
        };
        _this.getTutorialComplete = function (user) {
            if (user && user.quizStatus) {
                return true;
            }
            return false;
        };
        _this.getUserAccount = function (user) {
            if (user && user.ethAddress) {
                return utils_1.getFormattedEthAddress(user.ethAddress);
            }
            return "";
        };
        _this.openTutorialModal = function () {
            _this.setState({ isTutorialModalOpen: true });
        };
        _this.closeTutorialModal = function (user) {
            if (user && user.quizStatus) {
                _this.setState({ isTutorialModalOpen: false, isTutorialComplete: true });
            }
            else {
                _this.setState({ isTutorialModalOpen: false });
            }
        };
        _this.state = {
            isTutorialModalOpen: false,
            isTutorialComplete: false,
        };
        return _this;
    }
    UserTokenAccount.prototype.getTutorialState = function (loggedInState, tutorialComplete) {
        if (loggedInState === TOKEN_PROGRESS.ACTIVE) {
            return TOKEN_PROGRESS.DISABLED;
        }
        if (tutorialComplete) {
            return TOKEN_PROGRESS.COMPLETED;
        }
        return TOKEN_PROGRESS.ACTIVE;
    };
    UserTokenAccount.prototype.render = function () {
        var user = this.props.user;
        var accountSignupComplete = this.getAccountComplete(user);
        var tutorialComplete = this.getTutorialComplete(user);
        var userAccount = this.getUserAccount(user);
        var loggedInState = accountSignupComplete ? TOKEN_PROGRESS.COMPLETED : TOKEN_PROGRESS.ACTIVE;
        var tutorialState = this.getTutorialState(loggedInState, tutorialComplete);
        var buyState = accountSignupComplete && tutorialComplete ? TOKEN_PROGRESS.ACTIVE : TOKEN_PROGRESS.DISABLED;
        return (React.createElement(TokensStyledComponents_1.TokenAccountOuter, null,
            React.createElement(TokensStyledComponents_1.TokenAccountInner, null,
                React.createElement(TokensStyledComponents_1.TokenHeader, null, buyState === TOKEN_PROGRESS.ACTIVE ? React.createElement(TokensTextComponents_1.TokenBuySellHeaderText, null) : React.createElement(TokensTextComponents_1.TokenWelcomeHeaderText, null)),
                React.createElement(TokensStyledComponents_1.FlexColumns, null,
                    React.createElement(TokensStyledComponents_1.FlexColumnsPrimary, null,
                        !utils_1.isBrowserCompatible()
                            ? this.renderBrowserIncompatible()
                            : this.renderTokenSteps(loggedInState, tutorialState, buyState),
                        React.createElement(TokensAccountFaq_1.UserTokenAccountFaq, null)),
                    React.createElement(TokensStyledComponents_1.FlexColumnsSecondary, null,
                        React.createElement(TokensAccountProgress_1.UserTokenAccountProgress, { userAccount: userAccount, logInComplete: accountSignupComplete, tutorialComplete: tutorialComplete }),
                        React.createElement(TokensAccountPaypal_1.UserTokenAccountPaypal, null),
                        React.createElement(TokensAccountHelp_1.UserTokenAccountHelp, null))))));
    };
    return UserTokenAccount;
}(React.Component));
exports.UserTokenAccount = UserTokenAccount;
//# sourceMappingURL=Tokens.js.map