"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.RoomRateDescriptionFooter = void 0;
exports.default = RoomRateDescriptionTab;
const contexts_1 = require("../../../../../contexts/index.js");
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const Translation_1 = require("translations/Translation");
const BEButton_1 = __importDefault(require("../../../../generic/BEButton"));
const DatePicker_1 = __importDefault(require("../../../../generic/date/DatePicker"));
const Headline_1 = __importDefault(require("../../../../generic/Headline"));
const HtmlContentViewer_1 = require("../../../../generic/HtmlContentViewer");
const LineBreak_1 = __importDefault(require("../../../../generic/LineBreak"));
const TaxInclusionNotice_1 = require("../../../../generic/TaxInclusionNotice/TaxInclusionNotice");
const Text_1 = __importStar(require("../../../../generic/Text"));
const RoomDetailsPriceBlock_1 = __importDefault(require("../RoomDetailsPriceBlock"));
const BookNowButton_1 = __importDefault(require("./BookNowButton"));
const useRateDetails_1 = require("../../../../../hooks/useRateDetails");
const WindowSize_1 = require("../../../../../hooks/WindowSize");
const Color_1 = require("../../../../../util/Color");
const DataLayer_1 = __importStar(require("../../../../../util/DataLayer"));
const TextAlignment_1 = require("../../../../../util/TextAlignment");
const RoomRateDescriptionTab_module_scss_1 = __importDefault(require("./RoomRateDescriptionTab.module.scss"));
const RoomRateDescriptionFooter = (props) => {
    const { t } = (0, react_i18next_1.useTranslation)();
    const ccx = (0, react_1.useContext)(contexts_1.CompanyContext);
    const { rate } = props;
    let isLocked = false;
    if (rate.isMemberOnly && !ccx.signedInUser) {
        isLocked = true;
    }
    const bookButtonLabel = props.getButtonLabel ? props.getButtonLabel(false, false) : t(Translation_1.Translation.Misc.BookNow);
    const openSignupModalOnClick = () => {
        DataLayer_1.default.instance.sendInteraction('Member Signup Modal', DataLayer_1.InteractionType.LINK, DataLayer_1.InteractionStep.ROOMS);
        ccx.openMemberSignupModal();
    };
    const bookNowButton = isLocked ? (react_1.default.createElement(BEButton_1.default, { filled: true, success: true, onClick: openSignupModalOnClick }, t(Translation_1.Translation.Step.Room.RoomInfo.RevealPrice))) : (react_1.default.createElement(BookNowButton_1.default, { isFilled: true, rate: props.rate, buttonLabel: bookButtonLabel, onAddToBasketOverride: props.onAddToBasketOverride }));
    const priceBlock = react_1.default.createElement("div", { className: "u-flex flex-column align-items-start align-items-md-end justify-content-start" });
    return (react_1.default.createElement("div", { className: "u-flex" },
        priceBlock,
        react_1.default.createElement("div", { className: "u-flex align-items-center" }, bookNowButton)));
};
exports.RoomRateDescriptionFooter = RoomRateDescriptionFooter;
const Calendar = ({ row, rate }) => {
    const [selectedStartDate, setSelectedStartDate] = (0, react_1.useState)(null);
    const { updateBasketRow } = (0, react_1.useContext)(contexts_1.BasketContext);
    const { setRoomRateCalendarInteractivity } = (0, react_1.useContext)(contexts_1.BookingEngineContext);
    const startDate = row.getStartDate();
    const endDate = row.getEndDate();
    const roomCode = rate.getRoom().code || '';
    const rateCode = rate.code;
    const onStartDateChanged = (date) => {
        setSelectedStartDate(date);
    };
    const onEndDateChanged = (endDate) => {
        if (endDate && selectedStartDate) {
            // Ensure Room Rate Details modal state persists across room list re-render.
            const roomCode = rate.getRoom().code;
            if (rate.code && roomCode) {
                setRoomRateCalendarInteractivity({
                    rateCode: rate.code,
                    roomCode: roomCode,
                });
            }
            row.setEndDate(endDate);
            row.setStartDate(selectedStartDate);
            updateBasketRow(row, false);
        }
    };
    return (react_1.default.createElement("div", { className: `d-flex align-items-center flex-column ${RoomRateDescriptionTab_module_scss_1.default.calendarContainer}` },
        react_1.default.createElement(DatePicker_1.default, { showMonthOnLoad: startDate, showMultipleMonths: false, supportsMultiSelecting: true, showMinNightStay: false, supportsWeek: false, selectedStartDate: startDate, selectedEndDate: endDate, className: RoomRateDescriptionTab_module_scss_1.default.calendar, roomCode: roomCode, rateCode: rateCode, onStartDateChanged: onStartDateChanged, onEndDateChanged: onEndDateChanged })));
};
const RateDescriptionOverides = ({ rate }) => {
    var _a;
    const basketContext = (0, react_1.useContext)(contexts_1.BasketContext);
    const basketRow = (_a = basketContext.selectedBasketRow) !== null && _a !== void 0 ? _a : basketContext.currentBasketRows[basketContext.currentBasketRows.length - 1];
    const displayRates = rate.getDisplayRates({
        startDate: basketRow === null || basketRow === void 0 ? void 0 : basketRow.getStartDate(),
        endDate: basketRow === null || basketRow === void 0 ? void 0 : basketRow.getEndDate(),
    });
    const { t } = (0, react_i18next_1.useTranslation)();
    return (react_1.default.createElement("div", { className: "u-marg-top--medium" }, displayRates.map((displayRate, index) => (react_1.default.createElement("div", { className: "u-marg-bottom--light", key: index },
        displayRate.startDate && displayRate.endDate ? (react_1.default.createElement(react_1.default.Fragment, null,
            react_1.default.createElement(Text_1.default, null,
                react_1.default.createElement("strong", null, rate.displayRateToDayLabel(displayRate))),
            react_1.default.createElement(Text_1.default, null,
                rate.displayRateToDayName(displayRate),
                ": ",
                displayRate.name))) : (react_1.default.createElement(Text_1.default, { bold: true },
            t(Translation_1.Translation.Step.Room.RoomInfo.BaseRate),
            ": ",
            displayRate.name)),
        react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small },
            react_1.default.createElement("span", { className: "u-clear-font-weight", dangerouslySetInnerHTML: { __html: displayRate.shortDescription } })),
        react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small },
            react_1.default.createElement("span", { className: "u-clear-font-weight", dangerouslySetInnerHTML: { __html: displayRate.longDescription } })))))));
};
function RoomRateDescriptionTab(props) {
    const ccx = (0, react_1.useContext)(contexts_1.CompanyContext);
    const { selectedBasketRow } = (0, react_1.useContext)(contexts_1.BasketContext);
    const { t } = (0, react_i18next_1.useTranslation)();
    const { isMobile } = (0, WindowSize_1.useWindowSize)();
    const cancelPolicy = props.rate.getCancellationPolicy();
    const guaranteePolicy = props.rate.getGuaranteePolicy();
    let isLocked = false;
    if (props.rate.isMemberOnly && !ccx.signedInUser) {
        isLocked = true;
    }
    const rate = props.rate;
    const { rateName, shortDescription, longDescription } = (0, useRateDetails_1.useRateDetails)(rate, isLocked);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement("div", null,
            react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                react_1.default.createElement(Headline_1.default, { bold: true }, rateName)),
            react_1.default.createElement("div", { className: "u-marg-bottom--heavy" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, asDiv: true },
                    react_1.default.createElement(HtmlContentViewer_1.HtmlContentViewer, { content: longDescription ? longDescription : shortDescription !== null && shortDescription !== void 0 ? shortDescription : '' }))),
            react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                selectedBasketRow && react_1.default.createElement(Calendar, { row: selectedBasketRow, rate: rate }),
                react_1.default.createElement(RateDescriptionOverides, { rate: rate })),
            react_1.default.createElement(LineBreak_1.default, null),
            react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                react_1.default.createElement(Text_1.default, null,
                    react_1.default.createElement("strong", null, t(Translation_1.Translation.Step.Confirmation.Policies)))),
            react_1.default.createElement("div", { className: "u-marg-bottom--heavy" },
                (guaranteePolicy === null || guaranteePolicy === void 0 ? void 0 : guaranteePolicy.longDescription) && !guaranteePolicy.hide && (react_1.default.createElement("div", { className: "u-marg-bottom--heavy" },
                    react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                        react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small },
                            react_1.default.createElement("strong", null, t(Translation_1.Translation.Misc.GuaranteePolicy)))),
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, asDiv: true },
                        react_1.default.createElement(HtmlContentViewer_1.HtmlContentViewer, { content: guaranteePolicy.longDescription })))),
                react_1.default.createElement("div", { className: "u-marg-bottom--heavy" },
                    react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                        react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small },
                            react_1.default.createElement("strong", null, t(Translation_1.Translation.Misc.CancellationPolicy)))),
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, asDiv: true },
                        react_1.default.createElement(HtmlContentViewer_1.HtmlContentViewer, { content: cancelPolicy })))),
            react_1.default.createElement("div", { className: "u-flex flex-column align-items-start align-items-md-end justify-content-end" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Navy }, t(Translation_1.Translation.Misc.Total)),
                react_1.default.createElement(RoomDetailsPriceBlock_1.default, { isLocked: isLocked, averagePreDiscount: rate.getTotalPriceBeforeDiscount(), averagePrice: rate.getTotalPrice(), isMemberOnly: props.rate.isMemberOnly, hidePerNight: true }),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Label, color: Color_1.Color.DarkGrey, align: isMobile ? TextAlignment_1.TextAlign.Left : TextAlignment_1.TextAlign.Right },
                    react_1.default.createElement(TaxInclusionNotice_1.TaxInclusionNotice, { rate: rate }))))));
}
//# sourceMappingURL=RoomRateDescriptionTab.js.map