"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");
/*
 *  This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
const misc_1 = require("@cocalc/util/misc");
const theme_1 = require("@cocalc/util/theme");
const antd_1 = require("antd");
const in_place_sign_in_or_up_1 = __importDefault(require("components/auth/in-place-sign-in-or-up"));
const anonymous_1 = __importDefault(require("components/misc/anonymous"));
const loading_1 = __importDefault(require("components/share/loading"));
const config_1 = require("lib/config");
const profile_1 = __importDefault(require("lib/hooks/profile"));
const use_customize_1 = __importDefault(require("lib/use-customize"));
const router_1 = require("next/router");
const invoices_and_receipts_1 = __importDefault(require("./invoices-and-receipts"));
const menu_1 = __importDefault(require("./menu"));
const overview_1 = __importDefault(require("./overview"));
const payment_methods_1 = __importDefault(require("./payment-methods"));
const subscriptions_1 = __importDefault(require("./subscriptions"));
const { Content } = antd_1.Layout;
function ConfigLayout({ page }) {
    const { isCommercial } = (0, use_customize_1.default)();
    const router = (0, router_1.useRouter)();
    const profile = (0, profile_1.default)({ noCache: true });
    if (!isCommercial) {
        return ((0, jsx_runtime_1.jsx)(antd_1.Alert, { showIcon: true, style: {
                margin: "30px auto",
                maxWidth: "400px",
                fontSize: "12pt",
                padding: "15px 30px",
            }, type: "warning", message: "Billing is not enabled for this server." }));
    }
    if (!profile) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, { large: true, center: true });
    }
    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 see information about your licenses", onSuccess: () => {
                    router.reload();
                } }) }));
    }
    if (is_anonymous) {
        return (0, jsx_runtime_1.jsx)(anonymous_1.default, {});
    }
    // page could be an empty array, then main is undefined → overview page
    const [main] = page;
    function body() {
        // main must be in MainPages defined in [[..page]].tsx
        if (main == null)
            return (0, jsx_runtime_1.jsx)(overview_1.default, {});
        switch (main) {
            case "cards":
                return (0, jsx_runtime_1.jsx)(payment_methods_1.default, {});
            case "subscriptions":
                return (0, jsx_runtime_1.jsx)(subscriptions_1.default, {});
            case "receipts":
                return (0, jsx_runtime_1.jsx)(invoices_and_receipts_1.default, {});
            default:
                (0, misc_1.unreachable)(main);
        }
    }
    // this layout is the same as ../store/index.tsx
    return ((0, jsx_runtime_1.jsx)(antd_1.Layout, { style: {
            padding: "0 24px 24px",
            backgroundColor: "white",
            color: theme_1.COLORS.GRAY_D,
        }, children: (0, jsx_runtime_1.jsx)(Content, { style: {
                padding: 24,
                margin: 0,
                minHeight: 280,
            }, children: (0, jsx_runtime_1.jsxs)("div", { style: { maxWidth: config_1.MAX_WIDTH, margin: "auto" }, children: [(0, jsx_runtime_1.jsx)(menu_1.default, { main: main }), body()] }) }) }));
}
exports.default = ConfigLayout;
//# sourceMappingURL=layout.js.map