"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.RoomDetailsRetargeting = void 0;
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 Currency_1 = __importDefault(require("../../../generic/Currency"));
const Headline_1 = __importDefault(require("../../../generic/Headline"));
const Icon_1 = require("../../../generic/Icon/Icon");
const Pill_1 = __importStar(require("../../../generic/Pill"));
const TaxInclusionNotice_1 = require("../../../generic/TaxInclusionNotice/TaxInclusionNotice");
const Text_1 = __importStar(require("../../../generic/Text"));
const hooks_1 = require("../../../../hooks");
const FeaturedPromoFeature_1 = __importDefault(require("../../../../providers/feature/FeaturedPromoFeature"));
const ImageProvider_1 = require("../../../../providers/ImageProvider");
const Color_1 = require("../../../../util/Color");
const DataLayer_1 = __importStar(require("../../../../util/DataLayer"));
const ScreenSize_1 = __importDefault(require("../../../../util/ScreenSize"));
const ImageGallerySlider_1 = __importDefault(require("../ImageGallerySlider"));
const RoomModal_1 = __importDefault(require("../RoomModal"));
const RoomDetailsBedsBlock_1 = require("./RoomDetailsBedsBlock");
const RoomDetailsRetargeting = (props) => {
    const { room } = props;
    const [featuredRates, setFeaturedRates] = (0, react_1.useState)([]);
    const [standardRates, setStandardRates] = (0, react_1.useState)([]);
    const [viewingDescription, setViewingDescription] = (0, react_1.useState)(false);
    const context = react_1.default.useContext(contexts_1.BookingEngineContext);
    const basketContext = (0, react_1.useContext)(contexts_1.BasketContext);
    const { hotel } = (0, hooks_1.useCurrentHotel)();
    const { t } = (0, react_i18next_1.useTranslation)();
    (0, react_1.useEffect)(() => {
        var _a, _b, _c;
        let nonPromoRates = [];
        const toSetFeaturedRate = [];
        if (FeaturedPromoFeature_1.default.isActive()) {
            for (const currentRate of room.getRates()) {
                if (((_a = currentRate.promoCode) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_c = (_b = basketContext.selectedBasketRow) === null || _b === void 0 ? void 0 : _b.getPromoCode()) === null || _c === void 0 ? void 0 : _c.toLowerCase())) {
                    toSetFeaturedRate.unshift(currentRate);
                }
                else {
                    nonPromoRates.push(currentRate);
                }
            }
            if (toSetFeaturedRate.length > 0) {
                setFeaturedRates(toSetFeaturedRate);
            }
        }
        else {
            nonPromoRates = room.getRates();
        }
        setStandardRates(nonPromoRates);
    }, [room.getRates()]);
    const trimmedDescription = room.getShortDescription();
    const isMobile = context.screenSize <= ScreenSize_1.default.Large;
    const lowestPrice = Math.round(room.getLowestPrice(false, true));
    const currencySize = context.screenSize > ScreenSize_1.default.Medium && lowestPrice.toLocaleString().length < 7 ? 'large' : 'normal';
    const moreDetailsOnClick = () => {
        DataLayer_1.default.instance.sendInteraction('More Room Details', DataLayer_1.InteractionType.LINK, DataLayer_1.InteractionStep.ROOMS);
        setViewingDescription(true);
    };
    const closeDescriptionOnClose = () => {
        setViewingDescription(false);
    };
    return (react_1.default.createElement("div", { className: "room-details-container --theme-retargeting u-marg-top u-marg-bottom" },
        react_1.default.createElement("div", { className: "room-details" },
            react_1.default.createElement("div", { className: "room-details--image" },
                react_1.default.createElement(ImageGallerySlider_1.default, { images: room.getImages(), imageSize: ImageProvider_1.ImageSize.Medium })),
            react_1.default.createElement("div", { className: "room-details--content u-pad--heavy u-pad@l-" },
                react_1.default.createElement("div", { className: "u-marg-bottom" },
                    react_1.default.createElement("div", { className: "u-marg-bottom" },
                        react_1.default.createElement(Pill_1.default, { type: Pill_1.PillType.Primary, icon: Icon_1.IconType.Add }, t(Translation_1.Translation.Step.Room.YouBookedThisRoomRecently))),
                    react_1.default.createElement("div", { className: "room-details--content-title u-marg-bottom--light" },
                        react_1.default.createElement(Headline_1.default, { bold: true }, room.name)),
                    react_1.default.createElement(RoomDetailsBedsBlock_1.RoomDetailsBedsBlock, { room: room, textColor: Color_1.Color.Navy }),
                    react_1.default.createElement("div", { className: "room-details--content-description u-marg-bottom--light" },
                        react_1.default.createElement(Text_1.default, { color: Color_1.Color.Navy, type: Text_1.TextType.Small },
                            react_1.default.createElement("span", { dangerouslySetInnerHTML: { __html: (trimmedDescription === null || trimmedDescription === void 0 ? void 0 : trimmedDescription.replace(/<br(\/|)>/g, '')) || '' } })))),
                react_1.default.createElement("div", { className: "row" },
                    react_1.default.createElement("div", { className: "col-md-6 u-flex u-marg-bottom@m- flex-column align-items-start" },
                        react_1.default.createElement("div", { className: "room-details--content-perks u-marg-bottom@m-" }, isMobile && (react_1.default.createElement("div", { className: "u-marg-bottom" },
                            react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, bold: true, color: Color_1.Color.Accent }, (hotel === null || hotel === void 0 ? void 0 : hotel.perkTitle) || t(Translation_1.Translation.Misc.Perks.AndYouGetAll)))))),
                    react_1.default.createElement("div", { className: "col-md-6 u-flex justify-content-end flex-column align-items-start align-items-md-end" },
                        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: "room-details--content-price flex-row align-items-end" },
                            react_1.default.createElement(Headline_1.default, { size: currencySize, bold: true },
                                react_1.default.createElement(Currency_1.default, { hideDecimals: true }, lowestPrice)),
                            react_1.default.createElement(Text_1.default, { color: Color_1.Color.Navy, 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.Navy, className: "u-nowrap" },
                                react_1.default.createElement(TaxInclusionNotice_1.TaxInclusionNotice, { room: room }))),
                        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, { name: "ViewRatesNowButton", primary: true, filled: true, stopIconAnimation: true, iconPosition: "right", wide: context.screenSize <= ScreenSize_1.default.Large, onClick: moreDetailsOnClick }, t(Translation_1.Translation.Step.Room.RoomInfo.ViewRates))))))),
        react_1.default.createElement(RoomModal_1.default, { open: viewingDescription, room: props.room, rates: standardRates, featuredRates: featuredRates, onClose: closeDescriptionOnClose })));
};
exports.RoomDetailsRetargeting = RoomDetailsRetargeting;
//# sourceMappingURL=RoomDetailsRetargeting.js.map