"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 = BESummaryRoomRow;
const contexts_1 = require("../../contexts/index.js");
const hooks_1 = require("../../hooks/index.js");
const core_1 = require("@roomstay/core");
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const react_router_dom_1 = require("react-router-dom");
const Translation_1 = require("translations/Translation");
const BEButton_1 = __importDefault(require("../generic/BEButton"));
const Currency_1 = __importDefault(require("../generic/Currency"));
const LineBreak_1 = __importDefault(require("../generic/LineBreak"));
const Text_1 = __importStar(require("../generic/Text"));
const Tooltip_1 = __importDefault(require("../generic/Tooltip/Tooltip"));
const ImageGallerySlider_1 = __importDefault(require("../steps/room/ImageGallerySlider"));
const useSearchScopeHook_1 = require("../../hooks/useSearchScopeHook");
const ImageProvider_1 = require("../../providers/ImageProvider");
const Color_1 = require("../../util/Color");
const GetStepRoom_1 = __importDefault(require("../../util/GetStepRoom"));
const StringHelper_1 = __importDefault(require("../../util/StringHelper"));
function BESummaryRoomRow(props) {
    var _a, _b, _c, _d, _e, _f;
    const basketContext = (0, react_1.useContext)(contexts_1.BasketContext);
    const { currentStep } = (0, react_1.useContext)(contexts_1.FullPageEngineContext);
    const { isAccent2ColorDark, hotel } = (0, hooks_1.useCurrentHotel)();
    const { t } = (0, react_i18next_1.useTranslation)();
    const navigate = (0, react_router_dom_1.useNavigate)();
    const { showChildren } = (0, useSearchScopeHook_1.useSearchScopeHook)();
    const { index, row, showImages } = props;
    const totalPrice = row.getTotalPrice(true);
    const rate = row.getRate();
    const isSelected = ((_a = basketContext.selectedBasketRow) === null || _a === void 0 ? void 0 : _a.getID()) === row.getID();
    const isOnlyRate = basketContext.currentBasketRows.length === 1;
    const removeRate = t(isOnlyRate ? Translation_1.Translation.Step.Room.Summary.NoRemoveLastRate : Translation_1.Translation.Step.Room.Summary.RemoveThisRate);
    const rowFees = (_b = row.getRate()) === null || _b === void 0 ? void 0 : _b.getTotalFees();
    const rowTaxes = (_c = row.getRate()) === null || _c === void 0 ? void 0 : _c.getTotalTaxes();
    const rowItemisedFees = hotel && ((_d = row.getRate()) === null || _d === void 0 ? void 0 : _d.getItemisedFees((0, core_1.getFilteredBookingRateFees)((_e = hotel.fees) !== null && _e !== void 0 ? _e : [])));
    const cancelEditBasketRowOnClick = () => basketContext.clearSelectedRates(); //Set the selected basket row to null, ensuring that no row is selected for editing.
    const editOnClickHandler = () => {
        if (currentStep !== (0, GetStepRoom_1.default)()) {
            navigate((0, GetStepRoom_1.default)().getStepUrl());
        }
        basketContext.selectBasketRow(row);
        if (props.onEditPropertyClicked) {
            props.onEditPropertyClicked();
        }
    };
    const removeOnClickHandler = () => {
        if (currentStep !== (0, GetStepRoom_1.default)()) {
            navigate((0, GetStepRoom_1.default)().getStepUrl());
        }
        basketContext.removeBasketRow(row);
    };
    const promoApplied = row.isPromoCodeValid();
    const shouldTextBeWhite = isAccent2ColorDark && isSelected;
    const textWhiteOr = (color = Color_1.Color.Graphite) => {
        return shouldTextBeWhite ? Color_1.Color.White : color;
    };
    return (react_1.default.createElement(react_1.default.Fragment, null,
        index >= 1 && react_1.default.createElement(LineBreak_1.default, { noMargins: true, darker: true }),
        react_1.default.createElement("div", { key: row.getID(), className: 'booking-engine-summary--row' + (isSelected ? ' --selected' : '') },
            showImages && (react_1.default.createElement("div", { className: "u-border-rounded", style: { height: '190px' } },
                react_1.default.createElement(ImageGallerySlider_1.default, { images: row.getRoom().getImages(), imageSize: ImageProvider_1.ImageSize.Tiny }))),
            react_1.default.createElement("div", { className: "u-marg-top--light" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Label, color: textWhiteOr(Color_1.Color.DarkGrey) },
                    react_1.default.createElement("strong", null,
                        t(Translation_1.Translation.Step.Date.Room),
                        " ",
                        index + 1))),
            react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                react_1.default.createElement(Text_1.default, { color: textWhiteOr(Color_1.Color.Navy) },
                    react_1.default.createElement("strong", null, rate === null || rate === void 0 ? void 0 : rate.getRoom().name))),
            react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, rate === null || rate === void 0 ? void 0 : rate.name)),
            react_1.default.createElement("div", { className: "u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, t(Translation_1.Translation.Step.Date.Arrival)),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.Accent) }, row.getArrivalDate())),
            react_1.default.createElement("div", { className: "u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, t(Translation_1.Translation.Step.Date.Departure)),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.Accent) }, row.getDepartureDate())),
            react_1.default.createElement("div", { className: "u-marg-bottom--medium u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, [
                    StringHelper_1.default.pluralWithDictAndCount(row.getAdults(), Translation_1.Translation.Step.Date.Adult, t),
                    showChildren ? StringHelper_1.default.pluralWithDictAndCount(row.getChildren(), Translation_1.Translation.Step.Date.Child, t) : null,
                    ((_f = hotel === null || hotel === void 0 ? void 0 : hotel.childConfiguration) === null || _f === void 0 ? void 0 : _f.supportInfants) ? StringHelper_1.default.pluralWithDictAndCount(row.getInfants(), Translation_1.Translation.Step.Date.Infant, t) : null,
                ]
                    .filter((item) => !!item)
                    .join(`, `))),
            react_1.default.createElement("div", { className: "u-marg-top--light u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() },
                    t(Translation_1.Translation.Misc.Rates),
                    " (",
                    t(Translation_1.Translation.Misc.PerNight),
                    ")"),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.DarkGrey) },
                    react_1.default.createElement(Currency_1.default, null, rate === null || rate === void 0 ? void 0 : rate.getAveragePriceBeforeDiscount(true)))),
            promoApplied && (react_1.default.createElement("div", { className: "u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, t(Translation_1.Translation.Step.Date.PromoCode)),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.DarkGrey) }, row.getPromoCode()))),
            rate && (rate === null || rate === void 0 ? void 0 : rate.getTotalDiscount()) > 0 && (react_1.default.createElement("div", { className: "u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, t(Translation_1.Translation.Misc.Discount)),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.DarkGrey) },
                    react_1.default.createElement("span", { className: "u-ellip-overflow" }, "-"),
                    react_1.default.createElement(Currency_1.default, null, rate === null || rate === void 0 ? void 0 : rate.getTotalDiscount())))),
            react_1.default.createElement("div", { className: "u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, t(Translation_1.Translation.Step.General.RoomTotal)),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.DarkGrey) },
                    react_1.default.createElement(Currency_1.default, null, totalPrice))),
            !!rowFees && !rowItemisedFees && (
            // Only show fees if we don't have itemised fees. If we have itemised fees they will be shown later.
            react_1.default.createElement("div", { className: "u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, t(Translation_1.Translation.Step.Room.Summary.Fees)),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.DarkGrey) },
                    react_1.default.createElement(Currency_1.default, null, rowFees)))),
            !!rowTaxes && (react_1.default.createElement("div", { className: "u-marg-bottom--light u-flex" },
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr() }, t(Translation_1.Translation.Step.Room.Summary.Taxes)),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: textWhiteOr(Color_1.Color.DarkGrey) },
                    react_1.default.createElement(Currency_1.default, null, rowTaxes)))),
            react_1.default.createElement("div", { className: "u-marg-top u-marg-bottom u-flex justify-content-start" },
                isSelected ? (react_1.default.createElement(Tooltip_1.default, { title: t(Translation_1.Translation.Misc.Cancel) },
                    react_1.default.createElement("div", null,
                        react_1.default.createElement(BEButton_1.default, { isText: true, size: "tiny", primary: true, onClick: cancelEditBasketRowOnClick, textColor: textWhiteOr(Color_1.Color.Accent) }, t(Translation_1.Translation.Misc.Cancel))))) : (react_1.default.createElement(Tooltip_1.default, { title: t(Translation_1.Translation.Step.Confirmation.EditThisProperty) },
                    react_1.default.createElement("div", null,
                        react_1.default.createElement(BEButton_1.default, { isText: true, size: "tiny", primary: true, onClick: editOnClickHandler, textColor: textWhiteOr(Color_1.Color.Accent) }, t(Translation_1.Translation.Misc.Edit))))),
                react_1.default.createElement("span", { className: "u-pad-left--light u-pad-right--light", style: { color: Color_1.Color.LightGrey } }, "|"),
                react_1.default.createElement(Tooltip_1.default, { title: removeRate },
                    react_1.default.createElement("div", null,
                        react_1.default.createElement(BEButton_1.default, { isText: true, size: "tiny", primary: true, disabled: isOnlyRate, onClick: removeOnClickHandler, textColor: textWhiteOr(Color_1.Color.Accent) }, t(Translation_1.Translation.Misc.Remove))))))));
}
//# sourceMappingURL=BESummaryRoomRow.js.map