"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = StepConfirmationCheckoutDifferencesModal;
const contexts_1 = require("../../../contexts/index.js");
const dayjs_1 = __importDefault(require("dayjs"));
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const BEButton_1 = __importDefault(require("../../generic/BEButton"));
const Countdown_1 = __importDefault(require("../../generic/Countdown"));
const Currency_1 = __importDefault(require("../../generic/Currency"));
const Headline_1 = __importDefault(require("../../generic/Headline"));
const Icon_1 = require("../../generic/Icon/Icon");
const LineBreak_1 = __importDefault(require("../../generic/LineBreak"));
const SimpleModal_1 = __importStar(require("../../generic/modal/SimpleModal"));
const Pill_1 = __importStar(require("../../generic/Pill"));
const Text_1 = __importStar(require("../../generic/Text"));
const Translation_1 = require("../../../translations/Translation");
const Color_1 = require("../../../util/Color");
function StepConfirmationCheckoutDifferencesModal(props) {
    var _a, _b;
    const basketContext = (0, react_1.useContext)(contexts_1.BasketContext);
    const { t } = (0, react_i18next_1.useTranslation)();
    const [endTime, setEndTime] = (0, react_1.useState)((0, dayjs_1.default)().add(14, 'minute'));
    (0, react_1.useEffect)(() => {
        var _a;
        let cancelled = false;
        let timeout = null;
        if (!!props.differences.length || !!((_a = props.warnings) === null || _a === void 0 ? void 0 : _a.length)) {
            timeout = setTimeout(() => {
                if (!cancelled) {
                    props.onClose();
                }
            }, 740000);
        }
        return () => {
            cancelled = true;
            clearTimeout(timeout);
        };
    }, [props.differences.length, (_a = props.warnings) === null || _a === void 0 ? void 0 : _a.length]);
    const mobileFooter = (react_1.default.createElement("div", { className: "u-flex" },
        react_1.default.createElement(BEButton_1.default, { isText: true, size: "small", icon: Icon_1.IconType.ArrowLeft, onClick: props.onClose, isLoading: props.isLoading }, t(Translation_1.Translation.Step.Confirmation.TakeMeBack)),
        react_1.default.createElement(BEButton_1.default, { primary: true, filled: true, icon: Icon_1.IconType.ArrowRight, iconPosition: "right", onClick: props.onProceed, isLoading: props.isLoading }, t(Translation_1.Translation.Step.Confirmation.ContinueWithReservation))));
    return (react_1.default.createElement(SimpleModal_1.default, { open: !!props.differences.length || !!((_b = props.warnings) === null || _b === void 0 ? void 0 : _b.length), title: t(Translation_1.Translation.Step.Confirmation.YourTotalPriceHasChanged), mobileFooter: mobileFooter, desktopFooter: react_1.default.createElement("div", { className: "u-marg-heavy u-marg@m-" }, mobileFooter), size: SimpleModal_1.SimpleModalSize.Small, alignCenter: true },
        react_1.default.createElement("div", { className: "u-marg-heavy u-marg@m-" },
            react_1.default.createElement("div", { className: "row" },
                react_1.default.createElement("div", { className: "col-md-8" },
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small }, t(Translation_1.Translation.Step.Confirmation.ConfirmationCheckoutTitle))),
                react_1.default.createElement("div", { className: "col-md-4" },
                    react_1.default.createElement(Pill_1.default, { icon: Icon_1.IconType.Time, type: Pill_1.PillType.Primary },
                        react_1.default.createElement("span", { className: "u-marg-right--light" }, t(Translation_1.Translation.Step.Confirmation.RevertsIn)),
                        react_1.default.createElement(Countdown_1.default, { endTimeDate: endTime })))),
            react_1.default.createElement(LineBreak_1.default, null),
            !!(props.differences && props.differences.length) &&
                props.differences.map((difference) => {
                    var _a, _b, _c;
                    const basketRow = basketContext.getAllValidRows().find((row) => row.getID() === difference.id);
                    return (react_1.default.createElement("div", { key: difference.id },
                        !!basketRow && (react_1.default.createElement("div", { className: "u-marg-bottom--heavy" },
                            react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                                react_1.default.createElement(Headline_1.default, null, basketRow.getRoom().name)),
                            react_1.default.createElement(Text_1.default, null, (_a = basketRow.getRate()) === null || _a === void 0 ? void 0 : _a.name))),
                        react_1.default.createElement("div", { className: "u-flex u-marg-bottom--light" },
                            react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Body },
                                react_1.default.createElement("strong", null, "Displayed price:")),
                            react_1.default.createElement(Text_1.default, { color: Color_1.Color.Alert },
                                react_1.default.createElement(Currency_1.default, null, (_b = difference.totalPrice) === null || _b === void 0 ? void 0 : _b.before))),
                        react_1.default.createElement("div", { className: "u-flex" },
                            react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Body },
                                react_1.default.createElement("strong", null, "Actual price:")),
                            react_1.default.createElement(Text_1.default, { color: Color_1.Color.Success },
                                react_1.default.createElement(Currency_1.default, null, (_c = difference.totalPrice) === null || _c === void 0 ? void 0 : _c.after))),
                        react_1.default.createElement(LineBreak_1.default, null)));
                }),
            !!(props.warnings && props.warnings.length) &&
                props.warnings.map((warning, index) => {
                    return react_1.default.createElement(Text_1.default, { key: index }, warning);
                }))));
}
//# sourceMappingURL=StepConfirmationCheckoutDifferencesModal.js.map