"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.AuthenticatedUserModal = void 0;
const contexts_1 = require("../../../../contexts/index.js");
const hooks_1 = require("../../../../hooks/index.js");
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const react_router_dom_1 = require("react-router-dom");
const Icon_1 = __importStar(require("../../Icon/Icon"));
const LineBreak_1 = __importDefault(require("../../LineBreak"));
const Overlay_1 = require("../../Overlay/Overlay");
const Text_1 = __importDefault(require("../../Text"));
const WindowSize_1 = require("../../../../hooks/WindowSize");
const AccountRoutes_1 = require("../../../../pages/account/AccountRoutes");
const Translation_1 = require("../../../../translations/Translation");
const Color_1 = require("../../../../util/Color");
const ScreenSize_1 = __importDefault(require("../../../../util/ScreenSize"));
const AuthenticatedUserModal_module_scss_1 = __importDefault(require("./AuthenticatedUserModal.module.scss"));
const AuthenticatedUserModal = (props) => {
    const { open, anchorEl, containerEl, menuItems, placement, fallbackPlacements, onSignedOut, onClose, onCloseMenu } = props;
    const { hotel, isMemberPaymentInformationAvailable } = (0, hooks_1.useCurrentHotel)();
    const { logout } = (0, react_1.useContext)(contexts_1.AuthenticationContext);
    const { t } = (0, react_i18next_1.useTranslation)();
    const { screenSize } = (0, contexts_1.useBookingEngine)();
    const windowSize = (0, WindowSize_1.useWindowSize)();
    const isMobile = screenSize < ScreenSize_1.default.Large;
    const shouldBreakpoint = isMobile && (windowSize.height || 0) <= 705;
    const location = (0, react_router_dom_1.useLocation)();
    const onLogoutClick = () => {
        onClose === null || onClose === void 0 ? void 0 : onClose();
        onSignedOut === null || onSignedOut === void 0 ? void 0 : onSignedOut();
        logout();
    };
    const items = (0, react_1.useMemo)(() => {
        return (menuItems ||
            [
                {
                    icon: Icon_1.IconType.Person,
                    text: 'Account',
                    link: AccountRoutes_1.AccountRoutes.Home.path,
                },
                {
                    icon: Icon_1.IconType.Bed,
                    text: t(Translation_1.Translation.Navigation.Menu.YourReservations),
                    link: AccountRoutes_1.AccountRoutes.Reservations.path,
                },
                {
                    icon: Icon_1.IconType.Edit,
                    text: t(Translation_1.Translation.Navigation.Menu.ProfileInformation),
                    link: AccountRoutes_1.AccountRoutes.ProfileDetails.path,
                },
                {
                    icon: Icon_1.IconType.CreditCard,
                    text: t(Translation_1.Translation.Navigation.Menu.PaymentInformation),
                    link: AccountRoutes_1.AccountRoutes.CardDetails.path,
                    enabled: isMemberPaymentInformationAvailable,
                },
                {
                    icon: Icon_1.IconType.Info,
                    text: t(Translation_1.Translation.Navigation.Menu.NeedHelp),
                    link: AccountRoutes_1.AccountRoutes.Help.path,
                },
            ].filter((item) => item.enabled !== false));
    }, [hotel]);
    return (react_1.default.createElement(Overlay_1.Overlay, { preventScroll: shouldBreakpoint, usePortal: true, followElement: shouldBreakpoint ? null : anchorEl, placement: placement || 'auto-end', fallbackPlacements: fallbackPlacements, container: containerEl, open: open, onClose: onClose, strategy: "fixed", className: AuthenticatedUserModal_module_scss_1.default['logged-in-overlay'], containerClassName: (0, classnames_1.default)({
            [AuthenticatedUserModal_module_scss_1.default['logged-in-overlay-container--fixed']]: shouldBreakpoint,
        }) },
        react_1.default.createElement("div", { className: AuthenticatedUserModal_module_scss_1.default['list-items'] },
            items.map((item, index) => {
                return (react_1.default.createElement(react_router_dom_1.NavLink, { to: item.link, className: ({ isActive }) => {
                        const isCurrentPath = !!(item === null || item === void 0 ? void 0 : item.link) && location.pathname.toLowerCase().includes(item.link.toLowerCase());
                        return (0, classnames_1.default)(AuthenticatedUserModal_module_scss_1.default['list-item'], {
                            [AuthenticatedUserModal_module_scss_1.default['--selected']]: isActive || isCurrentPath,
                        });
                    }, key: index, onClick: () => {
                        onClose === null || onClose === void 0 ? void 0 : onClose();
                        onCloseMenu === null || onCloseMenu === void 0 ? void 0 : onCloseMenu();
                    } },
                    react_1.default.createElement("div", { className: AuthenticatedUserModal_module_scss_1.default['list-item--icon'] },
                        react_1.default.createElement(Icon_1.default, { icon: item.icon, color: Color_1.Color.Grey, size: "24px" })),
                    react_1.default.createElement(Text_1.default, null, item.text)));
            }),
            react_1.default.createElement(LineBreak_1.default, null),
            react_1.default.createElement("div", { className: AuthenticatedUserModal_module_scss_1.default['list-item'], onClick: onLogoutClick },
                react_1.default.createElement("div", { className: AuthenticatedUserModal_module_scss_1.default['list-item--icon'] },
                    react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.LogOut, color: Color_1.Color.Alert, size: "24px" })),
                react_1.default.createElement(Text_1.default, { color: Color_1.Color.Alert }, t(Translation_1.Translation.Misc.LogOut))))));
};
exports.AuthenticatedUserModal = AuthenticatedUserModal;
//# sourceMappingURL=AuthenticatedUserModal.js.map