"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.MemberSignInModal = void 0;
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 useSignedInMember_1 = require("../../../hooks/useSignedInMember");
const MemberPortalFeature_1 = __importDefault(require("../../../providers/feature/MemberPortalFeature"));
const RoomstayThemeEngine_1 = __importDefault(require("../../../providers/RoomstayThemeEngine"));
const Translation_1 = require("../../../translations/Translation");
const EmailAndFullnameMemberModal_1 = __importDefault(require("./EmailAndFullnameMemberModal"));
const EmailPasswordMemberModal_1 = __importDefault(require("./EmailPasswordMemberModal"));
const FamilyNameMemberModal_1 = __importDefault(require("./FamilyNameMemberModal"));
const InternalMemberSignInModal_1 = __importDefault(require("./InternalMemberSignInModal"));
const MemberPortalSignInModal_1 = __importDefault(require("./MemberPortalSignInModal"));
const MemberSignInModal = () => {
    const { externalMemberType, isExternalMemberHotel } = (0, useSignedInMember_1.useSignedInMember)();
    const { isSigningIn, closeMemberSignupModal, memberOnlyModalPromotion } = (0, react_1.useContext)(contexts_1.CompanyContext);
    const { t } = (0, react_i18next_1.useTranslation)();
    const { hotel } = (0, hooks_1.useCurrentHotel)();
    const memberLogo = (0, react_1.useMemo)(() => {
        // Preference promotion first
        if (memberOnlyModalPromotion === null || memberOnlyModalPromotion === void 0 ? void 0 : memberOnlyModalPromotion.memberOnlyModalImage) {
            return memberOnlyModalPromotion.memberOnlyModalImage;
        }
        if (hotel === null || hotel === void 0 ? void 0 : hotel.memberOnlyModalImage) {
            return hotel.memberOnlyModalImage;
        }
    }, [hotel === null || hotel === void 0 ? void 0 : hotel.memberOnlyModalImage, memberOnlyModalPromotion === null || memberOnlyModalPromotion === void 0 ? void 0 : memberOnlyModalPromotion.memberOnlyModalImage]);
    const imageSize = (0, react_1.useMemo)(() => {
        // Preference promotion first
        if (memberOnlyModalPromotion === null || memberOnlyModalPromotion === void 0 ? void 0 : memberOnlyModalPromotion.memberOnlyModalImageSize) {
            return memberOnlyModalPromotion.memberOnlyModalImageSize;
        }
        if (hotel === null || hotel === void 0 ? void 0 : hotel.memberOnlyModalImageSize) {
            return hotel.memberOnlyModalImageSize;
        }
    }, [hotel === null || hotel === void 0 ? void 0 : hotel.memberOnlyModalImageSize, memberOnlyModalPromotion === null || memberOnlyModalPromotion === void 0 ? void 0 : memberOnlyModalPromotion.memberOnlyModalImageSize]);
    if (isExternalMemberHotel) {
        switch (externalMemberType) {
            case core_1.EIntegration.Big4:
                return (react_1.default.createElement(FamilyNameMemberModal_1.default, { title: t(Translation_1.Translation.ExternalMemberPopup.Big4Title), image: memberLogo !== null && memberLogo !== void 0 ? memberLogo : RoomstayThemeEngine_1.default.getImageAssetUrl('big4-login.svg'), isOpen: isSigningIn, imageSize: imageSize !== null && imageSize !== void 0 ? imageSize : 'none' }));
            case core_1.EIntegration.RmsTop10:
                return (react_1.default.createElement(FamilyNameMemberModal_1.default, { title: t(Translation_1.Translation.ExternalMemberPopup.Top10Title), image: memberLogo !== null && memberLogo !== void 0 ? memberLogo : RoomstayThemeEngine_1.default.getImageAssetUrl('top10-login.svg'), isOpen: isSigningIn, imageSize: imageSize !== null && imageSize !== void 0 ? imageSize : 'none' }));
            case core_1.EIntegration.Top10:
                return (react_1.default.createElement(EmailPasswordMemberModal_1.default, { title: t(Translation_1.Translation.ExternalMemberPopup.Top10Title), image: memberLogo !== null && memberLogo !== void 0 ? memberLogo : RoomstayThemeEngine_1.default.getImageAssetUrl('top10-login.svg'), isOpen: isSigningIn, imageSize: imageSize !== null && imageSize !== void 0 ? imageSize : 'none' }));
            case core_1.EIntegration.Gday:
                return (react_1.default.createElement(FamilyNameMemberModal_1.default, { title: t(Translation_1.Translation.ExternalMemberPopup.GDayTitle), image: memberLogo !== null && memberLogo !== void 0 ? memberLogo : RoomstayThemeEngine_1.default.getImageAssetUrl('gday-login.svg'), isOpen: isSigningIn, imageSize: imageSize !== null && imageSize !== void 0 ? imageSize : 'none' }));
            case core_1.EIntegration.Salesforce:
                return (react_1.default.createElement(EmailAndFullnameMemberModal_1.default, { title: t(Translation_1.Translation.ExternalMemberPopup.SalesforceTitle), image: memberLogo !== null && memberLogo !== void 0 ? memberLogo : RoomstayThemeEngine_1.default.getImageAssetUrl('salesforce-login.png'), isOpen: isSigningIn, imageSize: imageSize !== null && imageSize !== void 0 ? imageSize : 'cover' }));
            case core_1.EIntegration.RAC:
                return (react_1.default.createElement(EmailAndFullnameMemberModal_1.default, { title: t(Translation_1.Translation.ExternalMemberPopup.RACTitle), image: memberLogo !== null && memberLogo !== void 0 ? memberLogo : RoomstayThemeEngine_1.default.getImageAssetUrl('rac-login.png'), isOpen: isSigningIn, imageSize: imageSize !== null && imageSize !== void 0 ? imageSize : 'contain', isMemberNumberRequired: hotel === null || hotel === void 0 ? void 0 : hotel.isRACMemberNoRequired }));
            default:
                return null;
        }
    }
    else {
        if (MemberPortalFeature_1.default.isActive()) {
            if (MemberPortalFeature_1.default.shouldUseMemberPortalForMemberPricing()) {
                // Users will need to create a full member portal account (with password and email verification) to
                // access member pricing.
                return react_1.default.createElement(MemberPortalSignInModal_1.default, { image: memberLogo, imageSize: imageSize !== null && imageSize !== void 0 ? imageSize : 'none', isOpen: isSigningIn, onClose: closeMemberSignupModal });
            }
            else {
                // Because Member Portal is enabled, the internal member signin modal will show the option to sign
                // in with an exististing account. But they won't be forced to set a password and verify their email
                // to access the member prices.
                return react_1.default.createElement(InternalMemberSignInModal_1.default, { image: memberLogo, isOpen: isSigningIn, onClose: closeMemberSignupModal });
            }
        }
        else {
            return react_1.default.createElement(InternalMemberSignInModal_1.default, { image: memberLogo, isOpen: isSigningIn, onClose: closeMemberSignupModal });
        }
    }
};
exports.MemberSignInModal = MemberSignInModal;
//# sourceMappingURL=MemberSignInModal.js.map