"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getServerSideProps = void 0;
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 antd_1 = require("antd");
const consts_1 = require("components/billing/consts");
const layout_1 = __importDefault(require("components/billing/layout"));
const footer_1 = __importDefault(require("components/landing/footer"));
const head_1 = __importDefault(require("components/landing/head"));
const header_1 = __importDefault(require("components/landing/header"));
const customize_1 = require("lib/customize");
const with_customize_1 = __importDefault(require("lib/with-customize"));
const error_1 = __importDefault(require("next/error"));
function Preferences(props) {
    const { customize, pageNotFound, page } = props;
    if (pageNotFound) {
        return (0, jsx_runtime_1.jsx)(error_1.default, { statusCode: 404 });
    }
    const subpage = page[0] != null ? ` - ${(0, misc_1.capitalize)(page[0])}` : "";
    return ((0, jsx_runtime_1.jsxs)(customize_1.Customize, { value: customize, children: [(0, jsx_runtime_1.jsx)(head_1.default, { title: `Billing${subpage}` }), (0, jsx_runtime_1.jsxs)(antd_1.Layout, { children: [(0, jsx_runtime_1.jsx)(header_1.default, {}), (0, jsx_runtime_1.jsx)(layout_1.default, { page: page }), (0, jsx_runtime_1.jsx)(footer_1.default, {})] })] }));
}
exports.default = Preferences;
async function getServerSideProps(context) {
    const { params, res } = context;
    const { page = [] } = params;
    // deprecated – https://github.com/sagemathinc/cocalc/issues/5739
    // see billing/layout.tsx for possible pages
    const [main] = page;
    switch (main) {
        // 307: temp redirect
        case "payment-methods":
            return res.redirect(307, "./cards");
        case "invoices-and-receipts":
            return res.redirect(307, "./receipts");
    }
    if (main != null && !consts_1.MainPages.includes(main)) {
        return (0, with_customize_1.default)({ context, props: { pageNotFound: true } });
    }
    return await (0, with_customize_1.default)({
        context,
        props: { page },
    });
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=%5B%5B...page%5D%5D.js.map