"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 react_add_to_calendar_1 = __importDefault(require("react-add-to-calendar"));
var utils_1 = require("@joincivil/utils");
var FullscreenModal_1 = require("../FullscreenModal");
var Button_1 = require("../Button");
var TransactionButton_1 = require("../TransactionButton");
var QuestionToolTip_1 = require("../QuestionToolTip");
var Checkbox_1 = require("../input/Checkbox");
var __1 = require("../");
var textComponents_1 = require("./textComponents");
var styledComponents_1 = require("./styledComponents");
function printThis() {
    window.print();
}
function getSaltyWords(salt) {
    if (!salt) {
        return "";
    }
    return utils_1.saltToWords(salt).join(" ");
}
function getReadableRevealDateRange(commitEndDate, revealEndDate) {
    var revealStartDateTime = utils_1.getLocalDateTimeStrings(commitEndDate + 1);
    var revealEndDateTime = utils_1.getLocalDateTimeStrings(revealEndDate);
    return "From " + revealStartDateTime[0] + " at " + revealStartDateTime[1] + " to " + revealEndDateTime[0] + " at " + revealEndDateTime[1];
}
function getCalendarEventDateTime(seconds) {
    var theDate = typeof seconds === "number" ? new Date(seconds * 1000) : seconds;
    var pad = function (num) {
        return utils_1.padString(num, 2, "0");
    };
    var hours = pad(theDate.getHours());
    var mins = pad(theDate.getMinutes());
    var tzOffset = "" + pad(theDate.getTimezoneOffset() / 60) + pad(theDate.getTimezoneOffset() % 60);
    var dateString = theDate.getFullYear() + "-" + pad(theDate.getMonth() + 1) + "-" + pad(theDate.getDate());
    var timeString = hours + ":" + mins + "-" + tzOffset;
    return dateString + "T" + timeString;
}
var AddRevealPhaseToCalendar = function (props) {
    // @TODO(jon): `textComponents` don't work here b/c these fields are plaintext. Let's
    // revisit converting JSX.Components to strings via textContent before this goes to mainnet
    var title = "Reveal My Vote for " + props.newsroomName + " on The Civil Registry";
    var description = "\n    " + props.listingDetailURL + "\n\n\n    My Secret Phrase\n\n    " + getSaltyWords(props.salt) + "\n\n\n    Challenge ID " + props.challengeID + "\n\n    I voted for " + props.newsroomName + " to be " + (props.voteOption === "0" ? "rejected from" : "accepted to") + " the Civil Registry\n\n\n    My Deposited CVL\n\n    " + props.numTokens + "\n  ";
    var location = props.listingDetailURL;
    var startTime = getCalendarEventDateTime(props.commitEndDate + 1);
    var endTime = getCalendarEventDateTime(props.revealEndDate);
    var event = {
        title: title,
        description: description,
        location: location,
        startTime: startTime,
        endTime: endTime,
    };
    return (React.createElement(styledComponents_1.StyledAddToCalendar, null,
        React.createElement(react_add_to_calendar_1.default, { event: event })));
};
var ReviewVote = /** @class */ (function (_super) {
    __extends(ReviewVote, _super);
    function ReviewVote() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            didSaveSalt: false,
        };
        _this.toggleHasSavedSalt = function () {
            _this.setState({ didSaveSalt: !_this.state.didSaveSalt });
        };
        return _this;
    }
    ReviewVote.prototype.render = function () {
        var _a = this.props, open = _a.open, challengeID = _a.challengeID, salt = _a.salt, commitEndDate = _a.commitEndDate, revealEndDate = _a.revealEndDate, isAppealChallenge = _a.isAppealChallenge, voteOption = _a.voteOption, newsroomName = _a.newsroomName, numTokens = _a.numTokens, userAccount = _a.userAccount, transactions = _a.transactions, postExecuteTransactions = _a.postExecuteTransactions, handleClose = _a.handleClose;
        var didSaveSalt = this.state.didSaveSalt;
        return (React.createElement(FullscreenModal_1.FullScreenModal, { open: open || false },
            React.createElement(styledComponents_1.ModalOuter, null,
                React.createElement(styledComponents_1.ModalContent, null,
                    React.createElement(styledComponents_1.StyledReviewVoteHeaderTitle, null,
                        React.createElement(textComponents_1.ReviewVoteHeaderTitleText, null)),
                    React.createElement(styledComponents_1.StyledReviewVoteContentCopy, null,
                        React.createElement(textComponents_1.ReviewVoteCopyText, { handlePrintClick: printThis })),
                    React.createElement(styledComponents_1.StyledReviewVoteContent, null,
                        React.createElement("div", null,
                            React.createElement(styledComponents_1.StyledReviewVoteDetails, null,
                                React.createElement(styledComponents_1.MetaRowSalt, null,
                                    React.createElement(styledComponents_1.MetaItemLabelSalt, null,
                                        React.createElement(textComponents_1.SaltLabelText, { challengeID: challengeID }),
                                        React.createElement(QuestionToolTip_1.QuestionToolTip, { explainerText: React.createElement(textComponents_1.SaltPhraseToolTipText, null), positionBottom: true })),
                                    React.createElement(styledComponents_1.MetaItemValueSalt, null, getSaltyWords(salt))),
                                React.createElement(styledComponents_1.MetaRow, null,
                                    React.createElement(styledComponents_1.MetaItemLabel, null,
                                        React.createElement(textComponents_1.ConfirmVotesLabelText, null)),
                                    React.createElement(styledComponents_1.MetaItemValueTwoCol, null,
                                        React.createElement(styledComponents_1.StyledConfirmVoteDateRange, null, getReadableRevealDateRange(commitEndDate, revealEndDate)),
                                        React.createElement(styledComponents_1.StyledAddToCalendarContainer, null,
                                            React.createElement(AddRevealPhaseToCalendar, __assign({}, this.props)),
                                            React.createElement("p", null, "Remember to set event to Private")))),
                                React.createElement(styledComponents_1.MetaRow, null,
                                    React.createElement(styledComponents_1.MetaItemLabel, null,
                                        "Challenge ID ",
                                        challengeID),
                                    React.createElement(styledComponents_1.MetaItemValue, null, isAppealChallenge ? (React.createElement(textComponents_1.AppealChallengeReviewVoteDecisionText, { voteOption: voteOption, newsroomName: newsroomName })) : (React.createElement(textComponents_1.ReviewVoteDecisionText, { voteOption: voteOption, newsroomName: newsroomName })))),
                                React.createElement(styledComponents_1.MetaRow, null,
                                    React.createElement(styledComponents_1.MetaItemLabel, null,
                                        React.createElement(textComponents_1.ReviewVoteDepositedCVLLabelText, null)),
                                    React.createElement(styledComponents_1.MetaItemValue, null, numTokens)),
                                React.createElement(styledComponents_1.MetaRow, null,
                                    React.createElement(styledComponents_1.MetaItemLabel, null,
                                        React.createElement(textComponents_1.ReviewVoteMyAddressLabelText, null)),
                                    React.createElement(styledComponents_1.MetaItemValueUser, null, userAccount && utils_1.getFormattedEthAddress(userAccount))))),
                        React.createElement(styledComponents_1.StyledDidSaveSaltContainer, null,
                            React.createElement("div", null,
                                React.createElement(Checkbox_1.Checkbox, { size: Checkbox_1.CheckboxSizes.SMALL, checked: didSaveSalt, onClick: this.toggleHasSavedSalt })),
                            React.createElement("div", null,
                                React.createElement(textComponents_1.SaveSaltCheckboxLabelText, null))),
                        React.createElement(styledComponents_1.StyledButtonContainer, null,
                            React.createElement(TransactionButton_1.TransactionButtonNoModal, { transactions: transactions, postExecuteTransactions: postExecuteTransactions, Button: __1.MetaMaskLogoButton, disabled: !didSaveSalt },
                                React.createElement(textComponents_1.TransactionButtonText, null)),
                            React.createElement(Button_1.CancelButton, { size: Button_1.buttonSizes.SMALL, onClick: handleClose }, "Cancel")),
                        React.createElement(styledComponents_1.StyledTransactionFinePrint, null,
                            React.createElement(textComponents_1.TransactionFinePrintText, null)))))));
    };
    return ReviewVote;
}(React.Component));
exports.ReviewVote = ReviewVote;
//# sourceMappingURL=ReviewVoteModal.js.map