"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 utils_1 = require("@joincivil/utils");
var styledComponents_1 = require("./styledComponents");
var QuestionToolTip_1 = require("../QuestionToolTip");
var TwoPhaseProgressBarCountdownTimerComponent = /** @class */ (function (_super) {
    __extends(TwoPhaseProgressBarCountdownTimerComponent, _super);
    function TwoPhaseProgressBarCountdownTimerComponent() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.renderCountdownProgressBars = function () {
            var primaryProgressBar = _this.renderPrimaryProgressBar();
            var secondaryProgressBar = _this.renderSecondaryProgressBar();
            var progressBars;
            if (_this.props.activePhaseIndex === 0) {
                progressBars = [primaryProgressBar, secondaryProgressBar];
            }
            else {
                progressBars = [secondaryProgressBar, primaryProgressBar];
            }
            return React.createElement(styledComponents_1.TwoPhaseProgressBarContainer, null, progressBars);
        };
        _this.renderPrimaryProgressBar = function () {
            var progress = _this.getProgress();
            var style = { width: (progress * 100).toString() + "%" };
            return (React.createElement(styledComponents_1.ProgressBarCountdownContainer, { key: "progressBarPrimary" },
                React.createElement(styledComponents_1.ProgressBarDisplayLabel, null,
                    _this.props.displayLabel,
                    React.createElement(QuestionToolTip_1.QuestionToolTip, { explainerText: _this.props.toolTipText, positionBottom: true })),
                React.createElement(styledComponents_1.ProgressBarCountdownTotal, null,
                    React.createElement(styledComponents_1.ProgressBarCountdownProgress, { style: style }))));
        };
        _this.renderSecondaryProgressBar = function () {
            var progress = _this.props.activePhaseIndex === 0 ? 0 : 1;
            var style = { width: (progress * 100).toString() + "%" };
            return (React.createElement(styledComponents_1.ProgressBarCountdownContainer, { key: "progressBarSecondary" },
                React.createElement(styledComponents_1.ProgressBarDisplayLabel, null,
                    _this.props.secondaryDisplayLabel,
                    React.createElement(QuestionToolTip_1.QuestionToolTip, { explainerText: _this.props.secondaryToolTipText, positionBottom: true })),
                React.createElement(styledComponents_1.ProgressBarCountdownTotal, null,
                    React.createElement(styledComponents_1.ProgressBarCountdownProgress, { style: style }))));
        };
        _this.renderExpiry = function () {
            var _a = utils_1.getLocalDateTimeStrings(_this.props.endTime), expiryDateString = _a[0], expiryTimeString = _a[1];
            return (React.createElement(styledComponents_1.ProgressBarCopy, null,
                "Newsroom listing ",
                _this.props.secondsRemaining > 0 ? "is" : "was",
                " ",
                _this.props.flavorText,
                " until",
                " ",
                expiryDateString,
                " ",
                expiryTimeString));
        };
        _this.renderReadableTimeRemaining = function () {
            if (_this.props.secondsRemaining > 0) {
                return (React.createElement(styledComponents_1.MetaItem, null,
                    React.createElement(styledComponents_1.MetaItemValueAccent, null, utils_1.getReadableDuration(_this.props.secondsRemaining)),
                    React.createElement(styledComponents_1.MetaItemLabel, null, "Remaining")));
            }
            return (React.createElement(styledComponents_1.MetaItem, null,
                React.createElement(styledComponents_1.MetaItemValueAccent, null, "Ended"),
                React.createElement(styledComponents_1.MetaItemLabel, null, "\u00A0")));
        };
        _this.getProgress = function () {
            if (_this.props.secondsRemaining > 0) {
                return 1 - _this.props.secondsRemaining / _this.props.totalSeconds;
            }
            return 1;
        };
        return _this;
    }
    TwoPhaseProgressBarCountdownTimerComponent.prototype.render = function () {
        return (React.createElement(styledComponents_1.StyledProgressBarCountdownTimer, null,
            this.renderCountdownProgressBars(),
            this.renderReadableTimeRemaining(),
            this.renderExpiry()));
    };
    return TwoPhaseProgressBarCountdownTimerComponent;
}(React.Component));
exports.TwoPhaseProgressBarCountdownTimerComponent = TwoPhaseProgressBarCountdownTimerComponent;
//# sourceMappingURL=TwoPhaseProgressBarCountdownTimer.js.map