"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoutesMenu = void 0;
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importStar(require("react"));
var access_1 = require("../../utility/access");
var react_router_dom_1 = require("react-router-dom");
var auth_1 = require("../Auth/auth");
var build_1 = require("../Build/build");
var v_eris_1 = require("v-eris");
require("./routes.menu.scss");
var RoutesMenu = function (props) {
    var _a = (0, react_1.useState)(false), profileExpanded = _a[0], setProfileExpanded = _a[1];
    var coreListWrap = (0, react_1.useRef)(null);
    var auth = (0, react_1.useContext)(auth_1.AuthContext);
    var lang = (0, react_1.useContext)(v_eris_1.LangContext);
    var build = (0, react_1.useContext)(build_1.BuildContext);
    var nav = (0, react_router_dom_1.useNavigate)();
    var routesList = (0, react_1.useMemo)(function () {
        var list = [];
        for (var key in build.routes) {
            var item = build.routes[key];
            if (item.access > auth.access || item.hidden)
                continue;
            list.push({ icon: item.icon, value: key, title: item.title });
        }
        ;
        return list;
    }, [build.routes]);
    (0, react_1.useEffect)(function () {
        var fn = function (event) {
            if (!coreListWrap.current)
                return;
            var inside = coreListWrap.current.contains(event.target);
            if (inside)
                return;
            setProfileExpanded(false);
        };
        document.addEventListener("mousedown", fn);
        return function () {
            document.removeEventListener("mousedown", fn);
        };
    }, [profileExpanded]);
    return (react_1.default.createElement("div", { className: "eris-routes-menu-container" },
        react_1.default.createElement("div", { className: "eris-routes-menu-profile" },
            react_1.default.createElement("div", { className: "eris-routes-menu-profile-user", onClick: function () { setProfileExpanded(!profileExpanded); } })),
        react_1.default.createElement("div", { className: v_eris_1.Props.className("eris-routes-menu-list", { expanded: profileExpanded }), ref: coreListWrap },
            react_1.default.createElement("div", { className: "eris-routes-menu-list-bg" }),
            react_1.default.createElement(v_eris_1.Column, { className: "eris-routes-menu-list-line" },
                react_1.default.createElement(v_eris_1.Row, null,
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-title" },
                        lang.get("Admin::Table::Users::Name"),
                        ":"),
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-value" }, auth.name)),
                react_1.default.createElement(v_eris_1.Row, null,
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-title" },
                        lang.get("Admin::Table::Users::Role"),
                        ":"),
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-value" }, auth.roleName)),
                react_1.default.createElement(v_eris_1.Row, null,
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-title" },
                        lang.get("Admin::Table::Users::Configuration"),
                        ":"),
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-value" }, auth.configurationName)),
                react_1.default.createElement(v_eris_1.Row, null,
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-title" },
                        lang.get("Admin::Table::Users::Access2"),
                        ":"),
                    react_1.default.createElement("span", { className: "eris-routes-menu-list-line-value" }, lang.get(access_1.AdminAccess["access::" + auth.access])))),
            react_1.default.createElement(v_eris_1.Select, { headerless: true, className: routesList.length < 2 ? "hidden" : "", value: build.route, onChange: function (event) { return nav(event.value); }, list: routesList }),
            react_1.default.createElement(v_eris_1.Row, { className: "eris-routes-menu-list-line eris-routes-menu-list-bottom", reverse: true },
                react_1.default.createElement(v_eris_1.Button, { onClick: function () {
                        if (auth.persona) {
                            auth.dispatch(["access", { value: 0 }]);
                        }
                        else {
                            auth.async.logout.fetch();
                        }
                        ;
                    } }, auth.persona ? lang.get("Auth::PersonaReLogin") : lang.get("Auth::LogOut"))))));
};
exports.RoutesMenu = RoutesMenu;
//# sourceMappingURL=routes.menu.js.map