"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");
/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var theme_1 = require("@cocalc/util/theme");
var antd_1 = require("antd");
var in_place_sign_in_or_up_1 = __importDefault(require("components/auth/in-place-sign-in-or-up"));
var anonymous_1 = __importDefault(require("components/misc/anonymous"));
var loading_1 = __importDefault(require("components/share/loading"));
var site_name_1 = __importDefault(require("components/share/site-name"));
var profile_1 = __importDefault(require("lib/hooks/profile"));
var use_customize_1 = __importDefault(require("lib/use-customize"));
var router_1 = require("next/router");
var react_1 = require("react");
var boost_1 = __importDefault(require("./boost"));
var cart_1 = __importDefault(require("./cart"));
var checkout_1 = __importDefault(require("./checkout"));
var congrats_1 = __importDefault(require("./congrats"));
var dedicated_1 = __importDefault(require("./dedicated"));
var menu_1 = __importDefault(require("./menu"));
var overview_1 = __importDefault(require("./overview"));
var site_license_1 = __importDefault(require("./site-license"));
var config_1 = require("lib/config");
var Content = antd_1.Layout.Content;
function StoreLayout(_a) {
    var page = _a.page;
    var isCommercial = (0, use_customize_1.default)().isCommercial;
    var router = (0, router_1.useRouter)();
    var profile = (0, profile_1.default)({ noCache: true });
    (0, react_1.useEffect)(function () {
        router.prefetch("/store/site-license");
    }, []);
    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: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["The ", (0, jsx_runtime_1.jsx)(site_name_1.default, {}), " store is not enabled."] }) }));
    }
    if (!profile) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, { large: true, center: true });
    }
    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 shop in the store", onSuccess: function () {
                    router.reload();
                } }) }));
    }
    if (is_anonymous) {
        return (0, jsx_runtime_1.jsx)(anonymous_1.default, {});
    }
    var _b = __read(page, 1), main = _b[0];
    function body() {
        switch (main) {
            case "site-license":
                return (0, jsx_runtime_1.jsx)(site_license_1.default, {});
            case "boost":
                return (0, jsx_runtime_1.jsx)(boost_1.default, {});
            case "dedicated":
                return (0, jsx_runtime_1.jsx)(dedicated_1.default, {});
            case "cart":
                return (0, jsx_runtime_1.jsx)(cart_1.default, {});
            case "checkout":
                return (0, jsx_runtime_1.jsx)(checkout_1.default, {});
            case "congrats":
                return (0, jsx_runtime_1.jsx)(congrats_1.default, {});
        }
        return (0, jsx_runtime_1.jsx)(overview_1.default, {});
    }
    return ((0, jsx_runtime_1.jsx)(antd_1.Layout, __assign({ style: {
            padding: "0 24px 24px",
            backgroundColor: "white",
            color: theme_1.COLORS.GRAY_D,
        } }, { children: (0, jsx_runtime_1.jsx)(Content, __assign({ style: {
                margin: 0,
                minHeight: "60vh",
            } }, { children: (0, jsx_runtime_1.jsxs)("div", __assign({ style: { maxWidth: config_1.MAX_WIDTH, margin: "auto" } }, { children: [(0, jsx_runtime_1.jsx)(menu_1.default, { main: main }), body()] })) })) })));
}
exports.default = StoreLayout;
//# sourceMappingURL=index.js.map