"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
var antd_1 = require("antd");
var config_1 = __importDefault(require("components/account/config"));
var A_1 = __importDefault(require("components/misc/A"));
var path_1 = require("path");
var base_path_1 = __importDefault(require("lib/base-path"));
var menu_1 = __importDefault(require("./menu"));
var is_browser_1 = __importDefault(require("lib/hooks/is-browser"));
var in_place_sign_in_or_up_1 = __importDefault(require("components/auth/in-place-sign-in-or-up"));
var register_1 = require("./register");
var icon_1 = require("@cocalc/frontend/components/icon");
var component_1 = __importDefault(require("./search/component"));
var avatar_1 = __importDefault(require("components/account/avatar"));
var profile_1 = __importDefault(require("lib/hooks/profile"));
var misc_1 = require("@cocalc/util/misc");
var loading_1 = __importDefault(require("components/share/loading"));
var router_1 = require("next/router");
var anonymous_1 = __importDefault(require("./anonymous"));
var Content = antd_1.Layout.Content, Sider = antd_1.Layout.Sider;
function ConfigLayout(_a) {
    var _b, _c;
    var page = _a.page;
    var router = (0, router_1.useRouter)();
    var isBrowser = (0, is_browser_1.default)();
    var profile = (0, profile_1.default)({ noCache: true });
    if (!profile) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, {});
    }
    var account_id = profile.account_id, is_anonymous = profile.is_anonymous;
    if (!account_id) {
        return ((0, jsx_runtime_1.jsx)(antd_1.Alert, { style: { margin: "15px auto" }, type: "warning", message: (0, jsx_runtime_1.jsx)(in_place_sign_in_or_up_1.default, { title: "Account Configuration", why: "to edit your account configuration", onSuccess: function () {
                    router.reload();
                } }) }));
    }
    if (is_anonymous) {
        return (0, jsx_runtime_1.jsx)(anonymous_1.default, {});
    }
    var _d = __read(page, 2), main = _d[0], sub = _d[1];
    var info = (_b = register_1.menu[main]) === null || _b === void 0 ? void 0 : _b[sub];
    var content = ((0, jsx_runtime_1.jsxs)(Content, __assign({ style: __assign({ padding: 24, margin: 0, minHeight: 280 }, ((info === null || info === void 0 ? void 0 : info.danger)
            ? { color: "#ff4d4f", backgroundColor: "#fff1f0" }
            : undefined)) }, { children: [(0, jsx_runtime_1.jsx)("div", __assign({ style: { float: "right", marginBottom: "15px" } }, { children: (0, jsx_runtime_1.jsx)(antd_1.Alert, { showIcon: true, type: "warning", message: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["This is the new config page.", " ", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ href: (0, path_1.join)(base_path_1.default, "settings"), external: true }, { children: "There is an old page..." }))] }) }) })), (0, jsx_runtime_1.jsxs)(antd_1.Space, __assign({ style: { marginBottom: "15px" } }, { children: [(0, jsx_runtime_1.jsx)(avatar_1.default, { account_id: account_id, style: { marginRight: "15px" } }), (0, jsx_runtime_1.jsxs)("div", __assign({ style: { color: "#666" } }, { children: [(0, jsx_runtime_1.jsxs)("b", __assign({ style: { fontSize: "13pt" } }, { children: [profile === null || profile === void 0 ? void 0 : profile.first_name, " ", profile === null || profile === void 0 ? void 0 : profile.last_name, profile.name ? " (@".concat(profile.name, ")") : ""] })), (0, jsx_runtime_1.jsx)("div", { children: "Your account" })] }))] })), main != "search" && (0, jsx_runtime_1.jsx)(component_1.default, {}), info && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("h2", { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: info.icon, style: { marginRight: "5px" } }), " ", (0, misc_1.capitalize)(main), " - ", info.title] }), info.desc, (0, jsx_runtime_1.jsx)(antd_1.Divider, {})] })), ((_c = info === null || info === void 0 ? void 0 : info.desc) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes("todo")) && ((0, jsx_runtime_1.jsx)(antd_1.Alert, { style: { margin: "15px auto", maxWidth: "600px" }, message: (0, jsx_runtime_1.jsx)("b", { children: "Under Constructions" }), description: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["This page is under construction. To configure your CoCalc account, visit", " ", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ href: (0, path_1.join)(base_path_1.default, "settings"), external: true }, { children: "Account Preferences" })), "."] }), type: "warning", showIcon: true })), (0, jsx_runtime_1.jsx)(config_1.default, { main: main, sub: sub })] })));
    return ((0, jsx_runtime_1.jsxs)(antd_1.Layout, { children: [(0, jsx_runtime_1.jsx)(Sider, __assign({ width: "30ex", breakpoint: "sm", collapsedWidth: "0" }, { children: isBrowser && (0, jsx_runtime_1.jsx)(menu_1.default, { main: main, sub: sub }) })), (0, jsx_runtime_1.jsx)(antd_1.Layout, __assign({ style: {
                    padding: "0 24px 24px",
                    backgroundColor: "white",
                    color: "#555",
                } }, { children: content }))] }));
}
exports.default = ConfigLayout;
//# sourceMappingURL=layout.js.map