"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 });
const react_1 = __importDefault(require("react"));
const react_i18next_1 = require("react-i18next");
const Translation_1 = require("translations/Translation");
const BEButton_1 = __importDefault(require("../../generic/BEButton"));
const Currency_1 = __importDefault(require("../../generic/Currency"));
const Headline_1 = __importDefault(require("../../generic/Headline"));
const Text_1 = __importStar(require("../../generic/Text"));
const ImageGallerySlider_1 = __importDefault(require("./ImageGallerySlider"));
const RoomRate_1 = require("../../../models/Room/RoomRate");
const Color_1 = require("../../../util/Color");
const StringHelper_1 = __importDefault(require("../../../util/StringHelper"));
const LargeRateCard = (props) => {
    const { t } = (0, react_i18next_1.useTranslation)();
    const room = props.rate.getRoom();
    const trimmedDescription = props.rate.description || props.rate.name;
    const updateRate = () => {
        props.onSelectRate();
    };
    // Calculate the price difference
    const ratePrice = props.rate.getAveragePrice();
    const selectedPrice = props.selectedRate.getAveragePrice();
    const priceDifference = ratePrice - selectedPrice;
    // Calculate current nights from the selected rate's night rates
    const currentNights = Object.keys(props.selectedRate.nightRates).length;
    // Only show minimum stay upgrades if they require longer stay AND are cheaper per night
    const minNightStay = props.rate.minNightStayOverride;
    const isMinStayUpgrade = minNightStay && minNightStay > currentNights && ratePrice < selectedPrice;
    // Calculate the extended checkout date for minimum stay upgrades
    const extendedCheckoutDate = props.startDate && minNightStay ? props.startDate.add(minNightStay, 'days') : null;
    return (react_1.default.createElement("div", { className: "upgrade-card upgrade-card--rate u-border-rounded" },
        react_1.default.createElement("div", { className: "upgrade-card__image" },
            react_1.default.createElement(ImageGallerySlider_1.default, { images: room.getImages() })),
        react_1.default.createElement("div", { className: "u-pad container" },
            react_1.default.createElement(Text_1.default, { bold: true }, room.name),
            react_1.default.createElement("div", { className: "u-marg-top--light" },
                react_1.default.createElement(Text_1.default, { bold: true, color: Color_1.Color.Accent }, props.rate.name),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.DarkGrey }, trimmedDescription)),
            react_1.default.createElement("div", { className: "u-flex flex-column no-gutters u-marg-top" },
                isMinStayUpgrade && (react_1.default.createElement(react_1.default.Fragment, null,
                    react_1.default.createElement("div", { className: "u-marg-bottom" },
                        react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Accent }, t(Translation_1.Translation.Step.Room.Upsell.ExtendYourStay, {
                            count: minNightStay - currentNights,
                            nights: StringHelper_1.default.pluralWithDict(minNightStay - currentNights, Translation_1.Translation.Misc.Night, t).toLowerCase(),
                        })),
                        extendedCheckoutDate && (react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Accent, bold: true, className: "u-marg-top-bottom--lighter" }, t(Translation_1.Translation.Step.Room.Upsell.ExtendCheckout, {
                            date: extendedCheckoutDate.format('MMM D, YYYY'),
                        }))),
                        react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.DarkGrey }, t(Translation_1.Translation.Step.Room.Upsell.MinimumStay, { minNightStay }))),
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Graphite }, t(Translation_1.Translation.Step.Room.Upsell.SaveWithLongerStay)),
                    react_1.default.createElement("div", { className: "u-flex u-flex-flex-start u-flex-align-center flex-row" },
                        react_1.default.createElement(Headline_1.default, { bold: true, color: Color_1.Color.Success },
                            react_1.default.createElement("span", { className: "u-flex align-items-center" },
                                react_1.default.createElement(Currency_1.default, { hideDecimals: true }, props.rate.getAveragePrice()))),
                        react_1.default.createElement(Text_1.default, { color: Color_1.Color.DarkGrey, inline: true },
                            "/",
                            t(Translation_1.Translation.Misc.Night))),
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Success, className: "upgrade-inline-price" },
                        react_1.default.createElement(react_i18next_1.Trans, { i18nKey: Translation_1.Translation.Step.Room.Upsell.SavePerNight, values: { amount: Math.abs(priceDifference) }, components: [
                                react_1.default.createElement(Currency_1.default, { key: 0, hideDecimals: true }, Math.abs(priceDifference)),
                            ] })))),
                !isMinStayUpgrade && (react_1.default.createElement(react_1.default.Fragment, null,
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Navy, inline: true }, t(Translation_1.Translation.Misc.From)),
                    react_1.default.createElement("div", { className: "u-flex u-flex-flex-start u-flex-align-center flex-row" },
                        react_1.default.createElement(Headline_1.default, { bold: true },
                            react_1.default.createElement("span", { className: "u-flex align-items-center" },
                                "+",
                                react_1.default.createElement(Currency_1.default, { hideDecimals: true }, priceDifference))),
                        react_1.default.createElement(Text_1.default, { color: Color_1.Color.DarkGrey, inline: true },
                            "/",
                            t(Translation_1.Translation.Misc.Night))))),
                react_1.default.createElement("div", { className: "u-marg-bottom" },
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Grey, inline: true, className: "u-nowrap" },
                        react_1.default.createElement("span", { dangerouslySetInnerHTML: {
                                __html: props.rate.getPriceType() === RoomRate_1.RoomRatePriceInclusion.IncludingFeesAndTaxes
                                    ? t(Translation_1.Translation.Step.Room.RoomInfo.IncludesTaxes)
                                    : t(Translation_1.Translation.Step.Room.ExcludingTaxes),
                            } }))),
                react_1.default.createElement("div", { className: "u-marg-top--light u-flex justify-content-end u-w-100@m-" },
                    react_1.default.createElement(BEButton_1.default, { onClick: updateRate, name: "UpgradeRateButton", primary: true, filled: true, wide: true }, t(Translation_1.Translation.Step.Room.Upgrade)))))));
};
exports.default = LargeRateCard;
//# sourceMappingURL=LargeRateCard.js.map