"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 get_requires_token_1 = __importDefault(require("@cocalc/server/auth/tokens/get-requires-token"));
const theme_1 = require("@cocalc/util/theme");
const antd_1 = require("antd");
const sign_up_1 = __importDefault(require("components/auth/sign-up"));
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 base_path_1 = __importDefault(require("lib/base-path"));
const customize_1 = require("lib/customize");
const with_customize_1 = __importDefault(require("lib/with-customize"));
const router_1 = require("next/router");
function SignUpPage({ customize, requiresToken }) {
    const { siteName, isCommercial } = customize;
    const router = (0, router_1.useRouter)();
    function openRoot() {
        router.push("/");
    }
    function onSuccess() {
        if (isCommercial) {
            setTimeout(openRoot, 2000); // make sure to open root after 2 secs, even if there is an error
            try {
                window.gtag?.("event", "conversion", {
                    send_to: `${theme_1.gtag_id}/${theme_1.sign_up_id}`,
                    event_callback: openRoot,
                });
            }
            catch (err) {
                console.warn("error sending gtag event", err);
            }
        }
        else {
            openRoot();
        }
    }
    return ((0, jsx_runtime_1.jsxs)(customize_1.Customize, { value: customize, children: [(0, jsx_runtime_1.jsx)(head_1.default, { title: `Sign up for ${siteName}` }), (0, jsx_runtime_1.jsxs)(antd_1.Layout, { children: [(0, jsx_runtime_1.jsx)(header_1.default, { page: "sign-up" }), (0, jsx_runtime_1.jsxs)(antd_1.Layout.Content, { style: { backgroundColor: "white" }, children: [(0, jsx_runtime_1.jsx)(sign_up_1.default, { requiresToken: requiresToken, onSuccess: onSuccess }), (0, jsx_runtime_1.jsx)(footer_1.default, {})] })] })] }));
}
exports.default = SignUpPage;
async function getServerSideProps(context) {
    const customize = await (0, with_customize_1.default)({ context });
    if (customize.props.customize.account != null) {
        // user is already signed in -- redirect them to top level page for now (todo).
        const { res } = context;
        res.writeHead(302, { location: base_path_1.default });
        res.end();
        return { props: {} };
    }
    customize.props.requiresToken = await (0, get_requires_token_1.default)();
    return customize;
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=sign-up.js.map