"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const antd_1 = require("antd");
const config_1 = __importDefault(require("components/account/config"));
const A_1 = __importDefault(require("components/misc/A"));
const path_1 = require("path");
const base_path_1 = __importDefault(require("lib/base-path"));
const menu_1 = __importDefault(require("./menu"));
const is_browser_1 = __importDefault(require("lib/hooks/is-browser"));
const in_place_sign_in_or_up_1 = __importDefault(require("components/auth/in-place-sign-in-or-up"));
const register_1 = require("./register");
const icon_1 = require("@cocalc/frontend/components/icon");
const component_1 = __importDefault(require("./search/component"));
const avatar_1 = __importDefault(require("components/account/avatar"));
const profile_1 = __importDefault(require("lib/hooks/profile"));
const misc_1 = require("@cocalc/util/misc");
const loading_1 = __importDefault(require("components/share/loading"));
const router_1 = require("next/router");
const anonymous_1 = __importDefault(require("./anonymous"));
const { Content, Sider } = antd_1.Layout;
function ConfigLayout({ page }) {
    const router = (0, router_1.useRouter)();
    const isBrowser = (0, is_browser_1.default)();
    const profile = (0, profile_1.default)({ noCache: true });
    if (!profile) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, {});
    }
    const { account_id, is_anonymous } = profile;
    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: () => {
                    router.reload();
                } }) }));
    }
    if (is_anonymous) {
        return (0, jsx_runtime_1.jsx)(anonymous_1.default, {});
    }
    const [main, sub] = page;
    const info = register_1.menu[main]?.[sub];
    const content = ((0, jsx_runtime_1.jsxs)(Content, { style: {
            padding: 24,
            margin: 0,
            minHeight: 280,
            ...(info?.danger
                ? { color: "#ff4d4f", backgroundColor: "#fff1f0" }
                : undefined),
        }, children: [(0, jsx_runtime_1.jsx)("div", { style: { float: "right", marginBottom: "15px" }, children: (0, jsx_runtime_1.jsx)(antd_1.Alert, { showIcon: true, type: "info", message: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["This is the account configuration page.", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: (0, path_1.join)(base_path_1.default, "settings"), external: true, children: "You can also adjust key preferences in the main app..." })] }) }) }), (0, jsx_runtime_1.jsxs)(antd_1.Space, { 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", { style: { color: "#666" }, children: [(0, jsx_runtime_1.jsxs)("b", { style: { fontSize: "13pt" }, children: [profile?.first_name, " ", profile?.last_name, profile.name ? ` (@${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, {})] })), info?.desc?.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, { 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, { 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, { style: {
                    padding: "0 24px 24px",
                    backgroundColor: "white",
                    color: "#555",
                }, children: content })] }));
}
exports.default = ConfigLayout;
//# sourceMappingURL=layout.js.map