"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 = UnavailableRoom;
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const AutoAutoHeight_1 = __importDefault(require("../../../../../animations/AutoAutoHeight"));
const BEButton_1 = __importDefault(require("../../../../generic/BEButton"));
const DatePicker_1 = __importDefault(require("../../../../generic/date/DatePicker"));
const Icon_1 = require("../../../../generic/Icon/Icon");
const Text_1 = __importStar(require("../../../../generic/Text"));
const contexts_1 = require("../../../../../contexts");
const hooks_1 = require("../../../../../hooks");
const RoomTypeFilter_1 = __importDefault(require("../../../../../models/Room/Filters/RoomTypeFilter"));
const Translation_1 = require("../../../../../translations/Translation");
const Color_1 = require("../../../../../util/Color");
const ScreenSize_1 = __importDefault(require("../../../../../util/ScreenSize"));
const UnavailableRoom_module_scss_1 = __importDefault(require("./UnavailableRoom.module.scss"));
function UnavailableRoom({ room, hideFindAvailableRooms }) {
    var _a, _b;
    const { t } = (0, react_i18next_1.useTranslation)();
    const { screenSize, currentFilters, setCurrentFilters } = (0, react_1.useContext)(contexts_1.BookingEngineContext);
    const { hotel } = (0, hooks_1.useCurrentHotel)();
    const basketContext = (0, react_1.useContext)(contexts_1.BasketContext);
    const basketRows = basketContext.currentBasketRows;
    const basketRow = (_a = basketContext.selectedBasketRow) !== null && _a !== void 0 ? _a : basketRows[basketRows.length - 1];
    const [startDate, setStartDate] = (0, react_1.useState)(null);
    const [endDate, setEndDate] = (0, react_1.useState)(null);
    const [openCalendar, setOpenCalendar] = (0, react_1.useState)(false);
    const toggleCalendar = () => setOpenCalendar((v) => !v);
    const selectDates = () => {
        if (startDate && endDate && room.code) {
            basketContext.setStartDate(startDate);
            basketContext.setEndDate(endDate);
            const updatedCurrentFilters = Object.assign({}, currentFilters);
            updatedCurrentFilters['RoomType'] = new RoomTypeFilter_1.default([room.code]);
            setCurrentFilters(updatedCurrentFilters);
        }
    };
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement("div", { className: (0, classnames_1.default)(UnavailableRoom_module_scss_1.default.container, { [UnavailableRoom_module_scss_1.default.calendarOpen]: openCalendar }) },
            react_1.default.createElement("div", { className: UnavailableRoom_module_scss_1.default.info },
                react_1.default.createElement(Text_1.default, { bold: true }, t(Translation_1.Translation.Step.Room.RoomInfo.Unfortunately)),
                react_1.default.createElement(Text_1.default, { color: Color_1.Color.Accent }, basketRow === null || basketRow === void 0 ? void 0 :
                    basketRow.getStartDate().format('ddd, DD MMM'),
                    " \u2014 ", basketRow === null || basketRow === void 0 ? void 0 :
                    basketRow.getEndDate().format('ddd, DD MMM')),
                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small }, t(Translation_1.Translation.Step.Room.RoomInfo.IsUnavailableForRoom, {
                    room: room.name,
                }))),
            !hideFindAvailableRooms && (react_1.default.createElement(BEButton_1.default, { className: UnavailableRoom_module_scss_1.default.findDatesBtn, name: "FindAvailableDatesButton", primary: true, primaryActive: openCalendar, filled: true, icon: openCalendar ? Icon_1.IconType.ArrowUp2 : Icon_1.IconType.ArrowDown2, iconPosition: "right", stopIconAnimation: true, textColor: (0, Color_1.getContrastTextColor)(openCalendar ? hotel === null || hotel === void 0 ? void 0 : hotel.colors.accent3 : hotel === null || hotel === void 0 ? void 0 : hotel.colors.accent), onClick: toggleCalendar, size: screenSize <= ScreenSize_1.default.Mobile ? 'small' : 'normal' }, t(Translation_1.Translation.Step.Room.RoomInfo.FindAvailableDatesForRoom))),
            react_1.default.createElement(AutoAutoHeight_1.default, { open: openCalendar, topOffset: 21 },
                react_1.default.createElement("div", { className: UnavailableRoom_module_scss_1.default.calendarOverlay },
                    react_1.default.createElement(DatePicker_1.default, { showMonthOnLoad: basketRow.getStartDate(), showMultipleMonths: screenSize > ScreenSize_1.default.ExtraLarge, supportsMultiSelecting: true, supportsWeek: false, className: UnavailableRoom_module_scss_1.default.calendar, roomCode: (_b = room.code) !== null && _b !== void 0 ? _b : '', small: true, onStartDateChanged: setStartDate, onEndDateChanged: setEndDate }),
                    react_1.default.createElement("div", { className: UnavailableRoom_module_scss_1.default.calendarFooter },
                        react_1.default.createElement(Text_1.default, { bold: true, color: startDate ? Color_1.Color.Accent : undefined }, startDate
                            ? `${startDate.format('ddd, DD MMM')}${endDate ? ` — ${endDate.format('ddd, DD MMM')}` : ''}`
                            : t(Translation_1.Translation.Step.Room.RoomInfo.SelectDate)),
                        react_1.default.createElement(BEButton_1.default, { primary: true, filled: true, onClick: selectDates, disabled: !(startDate && endDate), mobileWidth: true }, t(Translation_1.Translation.Step.Room.RoomInfo.SelectCheckoutDate))))))));
}
//# sourceMappingURL=UnavailableRoom.js.map