"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 __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
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 Button_1 = require("../Button");
var input_1 = require("../input/");
var QuestionToolTip_1 = require("../QuestionToolTip");
var styledComponents_1 = require("./styledComponents");
var textComponents_1 = require("./textComponents");
var VoteButton_1 = __importDefault(require("./VoteButton"));
var CommitVote = /** @class */ (function (_super) {
    __extends(CommitVote, _super);
    function CommitVote(props) {
        var _this = _super.call(this, props) || this;
        _this.renderTokenBalance = function () {
            var tokenBalanceLabel;
            var toolTipText;
            var displayBalance;
            var progress;
            if (_this.props.votingTokenBalance) {
                tokenBalanceLabel = React.createElement(textComponents_1.VotingTokenBalanceText, null);
                toolTipText = React.createElement(textComponents_1.VotingTokenBalanceTooltipText, null);
                displayBalance = _this.props.votingTokenBalanceDisplay;
                progress = _this.props.numTokens ? parseFloat(_this.props.numTokens) / _this.props.votingTokenBalance : 0;
            }
            else {
                tokenBalanceLabel = React.createElement(textComponents_1.AvailableTokenBalanceText, null);
                toolTipText = React.createElement(textComponents_1.AvailableTokenBalanceTooltipText, null);
                displayBalance = _this.props.tokenBalanceDisplay;
                progress = _this.props.numTokens ? parseFloat(_this.props.numTokens) / _this.props.tokenBalance : 0;
            }
            if (progress > 1) {
                progress = 1;
            }
            var style = { width: (progress * 100).toString() + "%" };
            return (React.createElement(React.Fragment, null,
                React.createElement(styledComponents_1.StyledBalanceRow, null,
                    React.createElement("div", null,
                        tokenBalanceLabel,
                        React.createElement(QuestionToolTip_1.QuestionToolTip, { explainerText: toolTipText, positionBottom: true })),
                    React.createElement(styledComponents_1.StyledBalanceRowRight, null, displayBalance)),
                React.createElement(styledComponents_1.ProgressBarTotal, null,
                    React.createElement(styledComponents_1.ProgressBarProgress, { style: style }))));
        };
        _this.renderNumTokensInput = function () {
            return (React.createElement(input_1.CurrencyInputWithButton, { placeholder: "0.00", name: "numTokens", buttonText: "Commit Max", icon: React.createElement(React.Fragment, null, "CVL"), value: _this.props.numTokens, onChange: _this.setNumTokens, onButtonClick: function () { return _this.props.onCommitMaxTokens(); } }));
        };
        _this.renderAppMessages = function () {
            var message;
            var _a = _this.props, numTokens = _a.numTokens, tokenBalance = _a.tokenBalance, votingTokenBalance = _a.votingTokenBalance;
            if (numTokens && parseFloat(numTokens) > tokenBalance + votingTokenBalance) {
                message = React.createElement(textComponents_1.CommitVoteInsufficientTokensText, null);
            }
            else if (numTokens && parseFloat(numTokens) === tokenBalance + votingTokenBalance) {
                message = React.createElement(textComponents_1.CommitVoteMaxTokensWarningText, null);
            }
            if (message) {
                return React.createElement(styledComponents_1.StyledAppMessage, null, message);
            }
            return null;
        };
        _this.setNumTokens = function (name, value) {
            var cleanValue = value && parseFloat(value);
            if (cleanValue) {
                cleanValue = Math.abs(cleanValue);
                _this.props.onInputChange({ numTokens: cleanValue });
                return;
            }
            _this.props.onInputChange({ numTokens: value });
        };
        _this.state = {
            numTokensError: undefined,
            displayStep: 0,
        };
        return _this;
    }
    CommitVote.prototype.render = function () {
        var _this = this;
        var canReview = this.props.voteOption !== undefined &&
            this.props.numTokens &&
            typeof parseInt(this.props.numTokens, 10) === "number";
        var DefaultCTATextComponent = this.props.isAppealChallenge
            ? textComponents_1.AppealChallengeVoteCallToActionText
            : textComponents_1.VoteCallToActionText;
        return (React.createElement(React.Fragment, null,
            React.createElement(styledComponents_1.StyledStep, { visible: this.state.displayStep === 0 },
                React.createElement(styledComponents_1.StyledStepLabel, null, "Step 1 of 2"),
                React.createElement(styledComponents_1.FormQuestion, null, this.props.children || React.createElement(DefaultCTATextComponent, { newsroomName: this.props.newsroomName })),
                React.createElement(styledComponents_1.VoteOptionsContainer, null,
                    React.createElement(VoteButton_1.default, __assign({ buttonVoteOptionValue: "1" }, this.props)),
                    React.createElement(styledComponents_1.StyledOrText, null, "or"),
                    React.createElement(VoteButton_1.default, __assign({ buttonVoteOptionValue: "0" }, this.props))),
                React.createElement(styledComponents_1.StyledVoteCTAButton, null,
                    React.createElement(Button_1.Button, { disabled: this.props.voteOption === undefined, onClick: function () { return _this.setState({ displayStep: 1 }); }, size: Button_1.buttonSizes.MEDIUM, theme: styledComponents_1.buttonTheme }, "Next"))),
            React.createElement(styledComponents_1.StyledStep, { visible: this.state.displayStep === 1 },
                React.createElement(styledComponents_1.StyledStepLabel, null, "Step 2 of 2"),
                React.createElement(styledComponents_1.FormQuestion, null,
                    React.createElement(textComponents_1.SelectNumTokensText, null)),
                React.createElement(styledComponents_1.StyledOneTokenOneVote, null,
                    React.createElement(textComponents_1.OneTokenOneVoteText, null),
                    React.createElement(QuestionToolTip_1.QuestionToolTip, { explainerText: React.createElement(textComponents_1.OneTokenOneVoteTooltipText, null), positionBottom: true })),
                this.renderTokenBalance(),
                this.renderNumTokensInput(),
                this.renderAppMessages(),
                React.createElement(styledComponents_1.StyledButtonsContainer, null,
                    React.createElement(Button_1.Button, { disabled: !canReview, size: Button_1.buttonSizes.MEDIUM, theme: styledComponents_1.buttonTheme, onClick: this.props.onReviewVote }, this.props.buttonText || React.createElement(textComponents_1.CommitVoteReviewButtonText, null)),
                    React.createElement("div", { onClick: function () { return _this.setState({ displayStep: 0 }); } },
                        React.createElement(styledComponents_1.StyledTextActionButton, null, "Back"))))));
    };
    return CommitVote;
}(React.Component));
exports.CommitVote = CommitVote;
//# sourceMappingURL=CommitVote.js.map