"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 react_1 = __importStar(require("react"));
const useSignedInMember_1 = require("../../../hooks/useSignedInMember");
const MemberPortalFeature_1 = __importDefault(require("../../../providers/feature/MemberPortalFeature"));
const InternalMemberSignInModal_1 = __importDefault(require("./InternalMemberSignInModal"));
const MemberPortalSignInModal_1 = __importDefault(require("./MemberPortalSignInModal"));
const MemberSignInModal = () => {
    const { isExternalMemberHotel } = (0, useSignedInMember_1.useSignedInMember)();
    const { memberProviderSigningIn, closeMemberSignupModal, memberOnlyModalPromotion, externalMembershipHandlers } = (0, react_1.useContext)(contexts_1.CompanyContext);
    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) {
        const handler = externalMembershipHandlers.find((handler) => handler.provider === memberProviderSigningIn);
        if (handler) {
            return handler.renderSignInModal();
        }
        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: !!memberProviderSigningIn, 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: !!memberProviderSigningIn, onClose: closeMemberSignupModal });
            }
        }
        else {
            return react_1.default.createElement(InternalMemberSignInModal_1.default, { image: memberLogo, isOpen: !!memberProviderSigningIn, onClose: closeMemberSignupModal });
        }
    }
};
exports.MemberSignInModal = MemberSignInModal;
//# sourceMappingURL=MemberSignInModal.js.map