"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCurrentHotel = void 0;
const contexts_1 = require("../contexts/index.js");
const core_1 = require("@roomstay/core");
const react_1 = require("react");
const NoCompanyContextError_1 = require("../errors/NoCompanyContextError");
const Color_1 = require("../util/Color");
const useCurrentHotel = () => {
    var _a, _b;
    try {
        const companyContext = (0, react_1.useContext)(contexts_1.CompanyContext);
        const hotel = companyContext.selectedHotel;
        if (!companyContext) {
            throw new NoCompanyContextError_1.NoCompanyContextError();
        }
        const isAccentColorDark = (0, react_1.useMemo)(() => {
            var _a;
            if (!((_a = hotel === null || hotel === void 0 ? void 0 : hotel.colors) === null || _a === void 0 ? void 0 : _a.accent))
                return false;
            return (0, Color_1.lightOrDark)(hotel.colors.accent) === 'dark';
        }, [(_a = hotel === null || hotel === void 0 ? void 0 : hotel.colors) === null || _a === void 0 ? void 0 : _a.accent]);
        const isAccent2ColorDark = (0, react_1.useMemo)(() => {
            var _a;
            if (!((_a = hotel === null || hotel === void 0 ? void 0 : hotel.colors) === null || _a === void 0 ? void 0 : _a.accent2))
                return false;
            return (0, Color_1.lightOrDark)(hotel.colors.accent2) === 'dark';
        }, [(_b = hotel === null || hotel === void 0 ? void 0 : hotel.colors) === null || _b === void 0 ? void 0 : _b.accent2]);
        const isPassthroughPayment = (hotel === null || hotel === void 0 ? void 0 : hotel.cardProcessor) === core_1.EHotelCardProcessor.Passthrough;
        const isMemberPaymentInformationAvailable = !hotel || (isPassthroughPayment && (hotel === null || hotel === void 0 ? void 0 : hotel.disableSavedPayments) !== true);
        return {
            hotel,
            isPassthroughPayment,
            isMemberPaymentInformationAvailable,
            isAccentColorDark,
            isAccent2ColorDark,
            changeHotel: (newHotelID) => {
                companyContext.changeHotel(newHotelID);
            },
        };
    }
    catch (ex) {
        // Masssive try /catch to isolate non-contextual uses of this hook
        console.error(ex);
        return {};
    }
};
exports.useCurrentHotel = useCurrentHotel;
//# sourceMappingURL=CurrentHotelHook.js.map