"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 input_1 = require("../input/");
var TransactionButton_1 = require("../TransactionButton");
var styledComponents_1 = require("./styledComponents");
var textComponents_1 = require("./textComponents");
var VoteButton_1 = __importDefault(require("./VoteButton"));
var StepCopy = function (props) {
    return (React.createElement(styledComponents_1.StyledStepCopy, null,
        React.createElement(styledComponents_1.StyledStepCopyNum, null, props.step),
        React.createElement("div", null, props.children)));
};
var RevealVote = /** @class */ (function (_super) {
    __extends(RevealVote, _super);
    function RevealVote(props) {
        var _this = _super.call(this, props) || this;
        _this.validateSalt = function () {
            var isValid = true;
            if (!_this.props.salt || _this.props.salt.length === 0) {
                isValid = false;
                _this.setState({
                    saltError: "Please enter a valid salt phrase",
                });
            }
            else {
                _this.setState({ saltError: undefined });
            }
            return isValid;
        };
        _this.onChange = function (name, value) {
            var _a;
            var validateFn;
            if (name === "salt") {
                validateFn = _this.validateSalt;
            }
            _this.props.onInputChange((_a = {}, _a[name] = value, _a), validateFn);
        };
        _this.state = { saltError: undefined };
        return _this;
    }
    RevealVote.prototype.render = function () {
        var canReveal = this.props.voteOption !== undefined && !this.state.saltError;
        return (React.createElement(React.Fragment, null,
            React.createElement(StepCopy, { step: "1" }, this.props.children || "Reveal the vote option you chose in the submit vote phase"),
            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(StepCopy, { step: "2" }, "Enter your 4-word voting code"),
            React.createElement(input_1.SaltInput, { salt: this.props.salt, name: "salt", onChange: this.onChange, invalid: !!this.state.saltError, invalidMessage: this.state.saltError }),
            React.createElement(styledComponents_1.StyledButtonsContainer, null,
                React.createElement(TransactionButton_1.TransactionButtonNoModal, { transactions: this.props.transactions, disabled: !canReveal, postExecuteTransactions: this.props.postExecuteTransactions },
                    React.createElement(textComponents_1.RevealVoteButtonText, null)))));
    };
    return RevealVote;
}(React.Component));
exports.RevealVote = RevealVote;
//# sourceMappingURL=RevealVote.js.map