"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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompanyContextWrapper = void 0;
const contexts_1 = require("../index.js");
const events_1 = require("../../events/index.js");
const hooks_1 = require("../../hooks/index.js");
const core_1 = require("@roomstay/core");
const react_1 = __importStar(require("react"));
const BookingAPI_1 = __importDefault(require("../../api/BookingAPI"));
const MemberPortalWidget_1 = require("../../engines/MemberPortalWidget/MemberPortalWidget");
const APIError_1 = require("../../errors/APIError");
const MemberOnlyFenceSignUp_1 = require("../../events/actions/MemberOnlyFence/MemberOnlyFenceSignUp");
const Big4MemberHandler_1 = require("../../handlers/membership/Big4MemberHandler");
const GdayMemberHandler_1 = require("../../handlers/membership/GdayMemberHandler");
const MemberJungleMemberHandler_1 = require("../../handlers/membership/MemberJungleMemberHandler");
const RACMemberHandler_1 = require("../../handlers/membership/RACMemberHandler");
const SalesforceMemberHandler_1 = require("../../handlers/membership/SalesforceMemberHandler");
const Top10MemberHandler_1 = require("../../handlers/membership/Top10MemberHandler");
const HotelDataSource_types_1 = require("../../models/Client/Hotel/HotelDataSource.types");
const StepHotel_1 = __importDefault(require("../../pages/steps/StepHotel/StepHotel"));
const CurrencyProvider_1 = __importDefault(require("../../providers/CurrencyProvider"));
const FilterProvider_1 = __importDefault(require("../../providers/FilterProvider"));
const LanguageProvider_1 = require("../../providers/LanguageProvider");
const RoomstayThemeEngine_1 = __importDefault(require("../../providers/RoomstayThemeEngine"));
const StaticContextProvider_1 = __importDefault(require("../../providers/StaticContextProvider"));
const AnalyticsEvents_1 = __importDefault(require("../../util/AnalyticsEvents/AnalyticsEvents"));
const currencyHelper = __importStar(require("../../util/CurrencyHelper"));
const DataLayer_1 = __importDefault(require("../../util/DataLayer"));
const StepManager_1 = __importDefault(require("../../util/StepManager"));
const TimeHelper_1 = __importDefault(require("../../util/TimeHelper"));
const CompanyContextWrapper = ({ configCompany: company, children }) => {
    var _a, _b, _c, _d;
    const beContext = (0, react_1.useContext)(contexts_1.BookingEngineContext);
    const getSelectedHotel = () => {
        for (const hotel of hotels) {
            if (selectedHotelID + '' === hotel.hotelID + '') {
                return hotel;
            }
        }
    };
    const [companyId, setCompanyId] = (0, react_1.useState)(company.companyId);
    const [name, setName] = (0, react_1.useState)(company.name);
    const [companyShort, setCompanyShort] = (0, react_1.useState)(company.companyShort);
    const [logo, setLogo] = (0, react_1.useState)(company.logo);
    const [colors, setColors] = (0, react_1.useState)(company.colors);
    const [hotels, setHotels] = (0, react_1.useState)(company.hotels);
    const [logoLink, setLogoLink] = (0, react_1.useState)(company.logoLink);
    const [privacyPolicyUrl, setPrivacyPolicyUrl] = (0, react_1.useState)(company.privacyPolicyUrl);
    const [selectedHotelID, setSelectedHotelID] = (0, react_1.useState)();
    const selectedHotel = (0, react_1.useMemo)(() => {
        for (const companyHotel of hotels) {
            if (selectedHotelID + '' === companyHotel.hotelID + '') {
                return companyHotel;
            }
        }
    }, [hotels, selectedHotelID]);
    const searchParams = new URLSearchParams(window.location.search);
    const currencyParam = searchParams.get('currency');
    const [currentCurrency, setCurrentCurrency] = (0, react_1.useState)((_b = currencyParam !== null && currencyParam !== void 0 ? currencyParam : (_a = getSelectedHotel()) === null || _a === void 0 ? void 0 : _a.defaultCurrency) !== null && _b !== void 0 ? _b : 'AUD');
    const [currentLanguage, setCurrentLanguage] = (0, react_1.useState)((_d = (_c = getSelectedHotel()) === null || _c === void 0 ? void 0 : _c.defaultLanguage) !== null && _d !== void 0 ? _d : LanguageProvider_1.Language.en_us);
    const [memberOnlyModalPromotion, setMemberOnlyModalPromotion] = (0, react_1.useState)(null);
    const [signedInUser, setSignedInUser] = (0, react_1.useState)(null);
    const [memberProviderSigningIn, setMemberProviderSigningIn] = (0, react_1.useState)(null);
    const allExternalMembershipHandlers = [
        (0, Big4MemberHandler_1.big4MemberHandler)(selectedHotel),
        (0, Top10MemberHandler_1.top10MemberHandler)(selectedHotel),
        (0, MemberJungleMemberHandler_1.memberJungleMemberHandler)(selectedHotel),
        (0, GdayMemberHandler_1.gdayMemberHandler)(selectedHotel),
        (0, SalesforceMemberHandler_1.salesforceMemberHandler)(selectedHotel),
        (0, RACMemberHandler_1.racMemberHandler)(selectedHotel),
    ];
    (0, react_1.useEffect)(() => {
        raise(new events_1.SelectedHotelChangeEvent(selectedHotel));
    }, [selectedHotel]);
    const { raise } = (0, hooks_1.useEvent)();
    const getHotelFromArrayWithId = (id, arrayOfHotels) => {
        for (const nextHotel of arrayOfHotels) {
            if (nextHotel.hotelID + '' === id + '') {
                return nextHotel;
            }
        }
    };
    const getHotelFromID = (id) => {
        return getHotelFromArrayWithId(id, hotels);
    };
    const updateHotel = (newHotel, callback) => {
        setHotels((oldHotels) => {
            let modified = false;
            const newHotelArray = oldHotels.map((mappingHotel) => {
                if (mappingHotel.hotelID + '' === newHotel.hotelID + '') {
                    modified = true;
                    const hotelDetails = {
                        name: newHotel.name,
                        hotelID: newHotel.hotelID,
                        hotelUrl: newHotel.hotelUrl,
                        currency: newHotel.defaultCurrency,
                        language: newHotel.defaultLanguage,
                        address: newHotel.address,
                    };
                    const event = new events_1.InitialHotelDetailsEvent(hotelDetails);
                    raise(event);
                    if (callback) {
                        return Object.assign({}, callback(mappingHotel));
                    }
                    return Object.assign({}, newHotel);
                }
                return Object.assign({}, mappingHotel);
            });
            if (!modified) {
                newHotelArray.push(newHotel);
                if (callback) {
                    // Fixed: Ensure the callback returns the hotel; otherwise, the UI may receive undefined.
                    callback(newHotel);
                }
            }
            return newHotelArray;
        });
    };
    const signUserIn = (user) => __awaiter(void 0, void 0, void 0, function* () {
        raise(new MemberOnlyFenceSignUp_1.MemberOnlyFenceSignUp(memberOnlyModalPromotion, user));
        DataLayer_1.default.instance.sendMemberSignUp();
        workingContext.closeMemberSignupModal();
        yield beContext.sessionProvider.updateSession({ user: user, memberId: user.memberNumber });
        setSignedInUser(user);
        // Set external ID for analytics tracking
        if (user.memberNumber) {
            AnalyticsEvents_1.default.setExternalId(user.memberNumber);
        }
        if (user.saveState) {
            yield beContext.storageProvider.setUser(user);
        }
    });
    const signUserOut = () => __awaiter(void 0, void 0, void 0, function* () {
        yield beContext.sessionProvider.updateSession({ user: undefined, memberId: undefined });
        yield beContext.storageProvider.setUser(undefined);
        setSignedInUser(null);
    });
    const getHotel = (0, react_1.useCallback)((hotelId, preloadedHotelDTO) => new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
        const currentHotelVersion = getHotelFromID(hotelId);
        const newHotel = Object.assign(Object.assign({}, currentHotelVersion), { 
            // Fixed: Specified Hotel not found
            // Ensure hotelID is set explicitly in case currentHotelVersion is undefined or missing it.
            hotelID: hotelId });
        let details;
        try {
            details = preloadedHotelDTO ? preloadedHotelDTO : yield BookingAPI_1.default.Hotel.fetchData(currentLanguage, newHotel);
        }
        catch (ex) {
            if (ex instanceof APIError_1.APIError) {
                console.error(ex);
                return;
            }
            else {
                return reject(ex);
            }
        }
        if (!details) {
            return;
        }
        updateHotel(newHotel, (updatedHotel) => {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
            updatedHotel.name = details.name;
            updatedHotel.address = details.address;
            updatedHotel.latitude = Number(details.latitude);
            updatedHotel.longitude = Number(details.longitude);
            updatedHotel.phone = details.phone;
            updatedHotel.checkInTime = TimeHelper_1.default.convert24To12hr(details.checkInTime);
            updatedHotel.checkOutTime = TimeHelper_1.default.convert24To12hr(details.checkOutTime);
            updatedHotel.paymentCardTypes = details.paymentCardTypes;
            updatedHotel.description = details.description;
            updatedHotel.locationDescription = details.locationDescription;
            updatedHotel.policies = details.policies;
            updatedHotel.hotelServices = details.hotelServices;
            updatedHotel.businessServices = details.businessServices;
            updatedHotel.rooms = details.rooms;
            updatedHotel.hasLoadedDetails = true;
            updatedHotel.dataSource = details.dataSource;
            updatedHotel.defaultCurrency = details.currencyCode;
            updatedHotel.cardProcessor = details.cardProcessor;
            updatedHotel.paymentMethods = details.paymentMethods;
            updatedHotel.planpay = details.planpay;
            updatedHotel.windcave = details.windcave;
            updatedHotel.hotelUrl = details.hotelUrl || updatedHotel.hotelUrl || '';
            updatedHotel.heroImage = details.heroImage || updatedHotel.heroImage || '';
            updatedHotel.images = details.images || [];
            updatedHotel.email = details.email;
            updatedHotel.roomGroups = details.roomGroups;
            updatedHotel.rmsUseDepositQuote = details.rmsUseDepositQuote;
            updatedHotel.checkAreaAvailabilityOnRoomStep = details.checkAreaAvailabilityOnRoomStep;
            updatedHotel.enableCreditCardSurcharge = details.enableCreditCardSurcharge;
            updatedHotel.integrations = details.integrations;
            updatedHotel.availableCountries = details.availableCountries;
            updatedHotel.preventCancellation = details.preventCancellation;
            updatedHotel.enableRoomUpsells = details.enableRoomUpsells;
            updatedHotel.enableRateUpsells = details.enableRateUpsells;
            if (updatedHotel.dataSource === HotelDataSource_types_1.HotelDataSource.Roomstay) {
                if (details.logo) {
                    updatedHotel.logo = details.logo;
                }
                if (details.colors) {
                    updatedHotel.colors = details.colors;
                }
                if (details.distanceUnitType) {
                    updatedHotel.distanceUnitType = details.distanceUnitType;
                }
                if (details.weekdayStartsOn) {
                    updatedHotel.startsWeekOnDay = details.weekdayStartsOn;
                }
                if (details.crossSellHotelIds) {
                    updatedHotel.crossSellHotelIds = details.crossSellHotelIds;
                }
                if (details.stateFieldConfiguration) {
                    updatedHotel.stateFieldConfiguration = details.stateFieldConfiguration;
                }
            }
            if (currentHotelVersion === null || currentHotelVersion === void 0 ? void 0 : currentHotelVersion.maxAdults) {
                //using HotelSpec maxAdults  from frontend
                updatedHotel.maxAdults = currentHotelVersion.maxAdults;
            }
            if (details.maxAdults !== undefined) {
                updatedHotel.maxAdults = details.maxAdults;
            }
            if (details.maxChildren !== undefined) {
                updatedHotel.maxChildren = details.maxChildren;
            }
            if (details.maxInfants !== undefined) {
                updatedHotel.maxInfants = details.maxInfants;
            }
            if (details.rooms) {
                //dymanic maxOccupancy from rooms database
                const roomArray = Object.values(details.rooms);
                if (roomArray.length) {
                    updatedHotel.maxOccupancy = roomArray.reduce((previousMax, current) => {
                        return Math.max(previousMax, current.maxOccupancy);
                    }, 0);
                }
            }
            updatedHotel.childConfiguration = details.childConfiguration;
            /**
             * Prioritized perks from roomstay-clients than roomstay-admin
             */
            updatedHotel.perks = ((_a = updatedHotel.perks) === null || _a === void 0 ? void 0 : _a.length) ? updatedHotel.perks : details.perks;
            updatedHotel.perkTitle = (_b = updatedHotel.perkTitle) !== null && _b !== void 0 ? _b : details.perkTitle;
            updatedHotel.countryPrefix = (_d = (_c = details.countryPrefix) !== null && _c !== void 0 ? _c : updatedHotel.countryPrefix) !== null && _d !== void 0 ? _d : '';
            updatedHotel.quoteImageDesktop = (_f = (_e = details.quoteImageDesktop) !== null && _e !== void 0 ? _e : updatedHotel.quoteImageDesktop) !== null && _f !== void 0 ? _f : '';
            updatedHotel.quoteImageMobile = (_h = (_g = details.quoteImageMobile) !== null && _g !== void 0 ? _g : updatedHotel.quoteImageMobile) !== null && _h !== void 0 ? _h : '';
            updatedHotel.memberOnlyImage = (_k = (_j = details.memberOnlyImage) !== null && _j !== void 0 ? _j : updatedHotel.memberOnlyImage) !== null && _k !== void 0 ? _k : '';
            if (details.memberOnlyRenderRateLast !== undefined) {
                updatedHotel.memberOnlyRenderRateLast = details.memberOnlyRenderRateLast;
            }
            updatedHotel.captureChildAge = details.captureChildAge;
            updatedHotel.fees = details.fees;
            updatedHotel.addDepositFeeToBookingTotal = details.addDepositFeeToBookingTotal;
            updatedHotel.company = details.company;
            updatedHotel.itineraryNote = details.itineraryNote;
            updatedHotel.minAdultAge = details.minAdultAge;
            updatedHotel.maxAdultAge = details.maxAdultAge;
            updatedHotel.countInfantsInOccupancy = details.countInfantsInOccupancy;
            updatedHotel.occupancyLimits = details.occupancyLimits;
            updatedHotel.preferProviderBookingId = details.preferProviderBookingId;
            updatedHotel.disableSavedPayments = details.disableSavedPayments;
            updatedHotel.showUnavailableRooms = details.showUnavailableRooms;
            updatedHotel.isRACMemberNoRequired = details.isRACMemberNoRequired;
            updatedHotel.countryCode = details.countryCode;
            updatedHotel.calendarHighlights = details.calendarHighlights;
            updatedHotel.addressRequirement = details.addressRequirement;
            updatedHotel.maxRoomsPerBooking = details.maxRoomsPerBooking;
            updatedHotel.bookingFlow = details.bookingFlow;
            updatedHotel.metaPixelId = details.metaPixelId;
            updatedHotel.enableAnalyticsDebug = details.enableAnalyticsDebug;
            resolve(updatedHotel);
            return updatedHotel;
        });
    })), []);
    (0, react_1.useEffect)(() => {
        setCompanyId(company.companyId);
        setName(company.name);
        setCompanyShort(company.companyShort);
        setLogo(company.logo);
        setColors(company.colors);
        setLogoLink(company.logoLink);
        setPrivacyPolicyUrl(company.privacyPolicyUrl);
        const configHotels = company.hotels.map((hotel) => {
            return Object.assign(Object.assign({}, hotel), { hasLoadedDetails: false, hotelID: `${hotel.hotelID}` });
        });
        setHotels(configHotels);
        if (company.selectedHotel) {
            const hotelId = typeof company.selectedHotel === 'string' ? company.selectedHotel : company.selectedHotel.hotelID + '';
            const targetHotel = getHotelFromArrayWithId(hotelId, configHotels);
            if (targetHotel) {
                setSelectedHotelID(hotelId);
            }
            else {
                // TODO: add centralized error logging
                console.log(`Unable to set selected hotel automatically. No Hotel found with ID: ${company.selectedHotel}`);
            }
        }
        else {
            /*
          We need to check if for some reason HotelStep isn't set as the first step,
          to automatically select a hotel, so engine doesn't fall over

          Possible TODO: We might need to do this on a new Step level, instead of here, as dynamically checking if StepHotel
          is first is probably not a great idea...
      */
            // Don't select hotel for MemberPortalWidget with groupWidgetConfig
            const isMemberPortalWithGroup = beContext.engine instanceof MemberPortalWidget_1.MemberPortalWidget && beContext.engine.getConfig().groupWidgetConfig;
            if (StepManager_1.default.getFirstStep() !== StepHotel_1.default && !isMemberPortalWithGroup) {
                setSelectedHotelID(configHotels[0].hotelID);
                console.log(`No selected hotel found - defaulting to ${configHotels[0].name}`);
            }
            else {
                RoomstayThemeEngine_1.default.registerStyles(company.colors);
            }
        }
    }, [company]);
    const onSelectedHotelIDChanged = react_1.default.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
        var _a, _b, _c;
        if (selectedHotelID) {
            const selectedHotel = yield getHotel(selectedHotelID);
            if (selectedHotel) {
                currencyHelper.loadExchangeRates((_a = selectedHotel.defaultCurrency) !== null && _a !== void 0 ? _a : 'AUD');
                StaticContextProvider_1.default.MemberOnlyRateCodes = (_b = selectedHotel.memberOnlyRates) !== null && _b !== void 0 ? _b : [];
                // Prep session based storage
                const sessionProvider = beContext.engine.getSessionProvider();
                yield sessionProvider.setHotelID(selectedHotelID);
                // Prep local storage (non-session based)
                beContext.storageProvider.setHotelId(selectedHotelID);
                // Reload current user?
                const user = yield beContext.storageProvider.getUser();
                if (user) {
                    yield signUserIn(user);
                }
                if (currencyParam && CurrencyProvider_1.default.getSymbol(currencyParam)) {
                    setCurrentCurrency(currencyParam);
                }
                else {
                    setCurrentCurrency(selectedHotel.defaultCurrency);
                }
                (_c = selectedHotel === null || selectedHotel === void 0 ? void 0 : selectedHotel.onLoad) === null || _c === void 0 ? void 0 : _c.call(selectedHotel);
            }
        }
    }), [selectedHotelID]);
    (0, react_1.useEffect)(() => {
        onSelectedHotelIDChanged();
    }, [onSelectedHotelIDChanged]);
    (0, react_1.useEffect)(() => {
        var _a;
        const selectedHotel = getSelectedHotel();
        DataLayer_1.default.instance.setCurrencyCodes(currentCurrency, (_a = selectedHotel === null || selectedHotel === void 0 ? void 0 : selectedHotel.defaultCurrency) !== null && _a !== void 0 ? _a : currentCurrency);
    }, [currentCurrency, selectedHotelID]);
    (0, react_1.useEffect)(() => {
        // Single-source GTM initialisation
        DataLayer_1.default.instance.initialiseGTM(company, selectedHotel);
    }, [company, selectedHotel]);
    // TODO: Add Hotel Details fetch
    // TODO: re-do fetch on language change
    const updateLowestPriceByTargetHotel = (targetHotel, value, isLoading) => {
        updateHotel(targetHotel, (hotel) => (Object.assign(Object.assign({}, hotel), { lowestPrice: { value, isLoading } })));
    };
    const getLowestPrice = (rooms) => {
        if (!(rooms === null || rooms === void 0 ? void 0 : rooms.length))
            return 0;
        const lowestDisplayPrice = rooms.reduce((min, room) => {
            // Get the lowest raw price for each room (see RoomDetails.tsx for reference)
            const lowestRawPrice = room.getLowestPrice(false, true);
            return lowestRawPrice != null && lowestRawPrice > 0 ? Math.min(min, lowestRawPrice) : min;
        }, Infinity);
        return isFinite(lowestDisplayPrice) ? lowestDisplayPrice : 0;
    };
    const workingContext = {
        currentLanguage,
        currentCurrency,
        memberOnlyModalPromotion,
        companyId,
        name,
        companyShort,
        logo,
        logoLink,
        privacyPolicyUrl,
        colors,
        hotels,
        signedInUser,
        selectedHotelID: selectedHotelID,
        updateLowestPricePerNightByHotelIds: (hotelIds, row) => __awaiter(void 0, void 0, void 0, function* () {
            hotelIds.forEach((hotelId) => {
                const targetHotel = getHotelFromID(hotelId);
                updateLowestPriceByTargetHotel(targetHotel, 0, true);
            });
            try {
                const filters = Object.values(beContext.currentFilters).filter(Boolean);
                const data = yield FilterProvider_1.default.getRoomListByHotelIds(row, filters, hotelIds, signedInUser === null || signedInUser === void 0 ? void 0 : signedInUser.memberNumber);
                for (const [hotelId, hotelData] of Object.entries(data)) {
                    const { hotel: latestHotelDTO, rooms } = hotelData;
                    try {
                        yield getHotel(hotelId, latestHotelDTO);
                        const targetHotel = getHotelFromID(hotelId);
                        const finalLowest = getLowestPrice(rooms);
                        updateLowestPriceByTargetHotel(targetHotel, finalLowest, false);
                    }
                    catch (_a) {
                        const targetHotel = getHotelFromID(hotelId);
                        updateLowestPriceByTargetHotel(targetHotel, 0, false);
                    }
                }
            }
            catch (error) {
                console.error(error);
            }
        }),
        changeHotel: (hotel) => {
            if (hotel === null) {
                setSelectedHotelID(undefined);
                return true;
            }
            const targetHotel = getHotelFromID(typeof hotel === 'string' ? hotel : hotel.hotelID + '');
            if (targetHotel) {
                setSelectedHotelID(targetHotel.hotelID);
                return true;
            }
            else {
                // TODO: add centralized error logging
                console.log(`Unable to set selected hotel automatically. No Hotel found with ID: ${company.selectedHotel}`);
                return false;
            }
        },
        closeMemberSignupModal: () => {
            setMemberProviderSigningIn(null);
            setMemberOnlyModalPromotion(null);
        },
        openMemberSignupModal: (provider) => {
            if (provider) {
                setMemberProviderSigningIn(provider);
            }
            else {
                const firstConfiguredHandler = allExternalMembershipHandlers.find((handler) => handler.isAvailable);
                if (firstConfiguredHandler) {
                    // If any external handler is available, default to that
                    setMemberProviderSigningIn(firstConfiguredHandler.provider);
                }
                else {
                    setMemberProviderSigningIn(core_1.EMembershipProvider.Internal);
                }
            }
        },
        signUserIn,
        signUserOut,
        setCurrentCurrency,
        setCurrentLanguage,
        getHotel,
        selectedHotel,
        memberProviderSigningIn,
        isExternalMemberHotel: allExternalMembershipHandlers.some((handler) => handler.isAvailable),
        externalMembershipHandlers: allExternalMembershipHandlers.filter((handler) => handler.isAvailable),
    };
    return react_1.default.createElement(contexts_1.CompanyContext.Provider, { value: workingContext }, children);
};
exports.CompanyContextWrapper = CompanyContextWrapper;
//# sourceMappingURL=CompanyContextWrapper.js.map