"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GroupedCheckInOutTimes = void 0;
const react_1 = __importDefault(require("react"));
const react_i18next_1 = require("react-i18next");
const Translation_1 = require("translations/Translation");
const TimeHelper_1 = __importDefault(require("../../../util/TimeHelper"));
const SmallSpinner_1 = __importDefault(require("../loader/SmallSpinner"));
const GroupedCheckInOutTimes = ({ hotel, wrapperClassName, colClassName, CheckInRender, CheckOutRender, LineRender }) => {
    var _a;
    const { t } = (0, react_i18next_1.useTranslation)();
    if (!hotel)
        return (react_1.default.createElement("div", { className: wrapperClassName },
            react_1.default.createElement("div", { className: "d-flex justify-content-center align-items-center", style: {
                    width: '100%',
                    height: '100%',
                } },
                react_1.default.createElement(SmallSpinner_1.default, null))));
    const defaultCheckInTime = hotel.checkInTime;
    const defaultCheckOutTime = hotel.checkOutTime;
    const roomGroups = (_a = hotel.roomGroups) !== null && _a !== void 0 ? _a : [];
    const hasCustomTimes = roomGroups.some(({ checkInTime, checkOutTime }) => !!checkInTime || !!checkOutTime);
    const checkInLines = [];
    const checkOutLines = [];
    if (hasCustomTimes) {
        roomGroups.forEach(({ groupName, checkInTime, checkOutTime }) => {
            const checkInFormatted = checkInTime ? TimeHelper_1.default.convert24To12hr(checkInTime) : defaultCheckInTime;
            const checkOutFormatted = checkOutTime ? TimeHelper_1.default.convert24To12hr(checkOutTime) : defaultCheckOutTime;
            checkInLines.push(`${groupName}: ${checkInFormatted}`);
            checkOutLines.push(`${groupName}: ${checkOutFormatted}`);
        });
    }
    else {
        checkInLines.push(`${t(Translation_1.Translation.Misc.After)} ${defaultCheckInTime}`);
        checkOutLines.push(`${t(Translation_1.Translation.Misc.Before)} ${defaultCheckOutTime}`);
    }
    return (react_1.default.createElement("div", { className: wrapperClassName },
        react_1.default.createElement("div", { className: colClassName },
            react_1.default.createElement(CheckInRender, null),
            checkInLines.map((line, index) => (react_1.default.createElement(LineRender, { key: `checkin-${index}`, line: line })))),
        react_1.default.createElement("div", { className: colClassName },
            react_1.default.createElement(CheckOutRender, null),
            checkOutLines.map((line, index) => (react_1.default.createElement(LineRender, { key: `checkout-${index}`, line: line }))))));
};
exports.GroupedCheckInOutTimes = GroupedCheckInOutTimes;
//# sourceMappingURL=GroupedCheckInOutTimes.js.map