"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 © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
const r_human_list_1 = require("@cocalc/frontend/components/r_human_list");
const antd_1 = require("antd");
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 main_1 = __importDefault(require("components/landing/main"));
const sanitized_markdown_1 = __importDefault(require("components/misc/sanitized-markdown"));
const sso_1 = require("components/sso");
const base_path_1 = __importDefault(require("lib/base-path"));
const customize_1 = require("lib/customize");
const sso_2 = require("lib/sso/sso");
const with_customize_1 = __importDefault(require("lib/with-customize"));
const link_1 = __importDefault(require("next/link"));
const path_1 = require("path");
const _1 = require(".");
const { Paragraph, Text } = antd_1.Typography;
function Signup(props) {
    const { id, descr, display, icon, domains, customize } = props;
    function renderDescr() {
        const fallback = `If you have an account at this provider,
    you can signup here to get access to ${customize.siteName}.`;
        const md = `## ${display}\n\n${descr ?? fallback}`;
        return (0, jsx_runtime_1.jsx)(sanitized_markdown_1.default, { value: md });
    }
    function renderIcon() {
        if (icon == null)
            return null;
        return ((0, jsx_runtime_1.jsx)("div", { style: { float: "right" }, children: (0, jsx_runtime_1.jsx)("img", { src: icon, width: 100, height: 100 }) }));
    }
    function renderExclusiveDomains() {
        if (domains.length === 0)
            return null;
        return ((0, jsx_runtime_1.jsxs)(Paragraph, { children: ["This is required for email addresses at", " ", (0, r_human_list_1.r_human_list)((domains ?? []).map((d) => ((0, jsx_runtime_1.jsx)(Text, { code: true, children: d }, d))))] }));
    }
    function renderButton() {
        const href = (0, path_1.join)(base_path_1.default, "auth", id);
        return ((0, jsx_runtime_1.jsxs)(antd_1.Button, { href: href, type: "primary", size: "large", style: { marginTop: "50px" }, children: ["Sign up using ", display] }));
    }
    function main() {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [renderIcon(), renderDescr(), renderExclusiveDomains(), renderButton()] }));
    }
    function nav() {
        return [...(0, sso_1.ssoNav)(), (0, jsx_runtime_1.jsx)(link_1.default, { href: `/sso/{id}`, children: display })];
    }
    return ((0, jsx_runtime_1.jsxs)(customize_1.Customize, { value: customize, children: [(0, jsx_runtime_1.jsx)(head_1.default, { title: `${_1.SSO_SUBTITLE} – ${display}` }), (0, jsx_runtime_1.jsxs)(antd_1.Layout, { style: { background: "white" }, children: [(0, jsx_runtime_1.jsx)(header_1.default, {}), (0, jsx_runtime_1.jsx)(main_1.default, { nav: nav(), children: main() }), (0, jsx_runtime_1.jsx)(footer_1.default, {})] })] }));
}
exports.default = Signup;
async function getServerSideProps(context) {
    const { id } = context.params;
    const info = await (0, sso_2.getOneSSO)(id);
    return await (0, with_customize_1.default)({ context, props: { ...info } });
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=%5Bid%5D.js.map