"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getServerSideProps = exports.SSO_SUBTITLE = 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 misc_1 = require("@cocalc/util/misc");
const antd_1 = require("antd");
const sso_1 = require("components/auth/sso");
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 sso_2 = require("components/sso");
const customize_1 = require("lib/customize");
const sso_3 = require("lib/sso/sso");
const with_customize_1 = __importDefault(require("lib/with-customize"));
const link_1 = __importDefault(require("next/link"));
const { Paragraph, Text } = antd_1.Typography;
exports.SSO_SUBTITLE = "Single Sign On";
function SignupIndex(props) {
    const { customize, ssos } = props;
    function renderDomains(domains) {
        if (domains == null || domains.length === 0)
            return;
        return (0, jsx_runtime_1.jsx)(Text, { type: "secondary", children: (0, misc_1.to_human_list)(domains ?? []) });
    }
    function extra(sso) {
        return (0, jsx_runtime_1.jsx)(link_1.default, { href: `/sso/${sso.id}`, children: "more" });
    }
    function renderSSOs() {
        return ssos.map((sso) => {
            const strategy = {
                name: sso.id,
                size: 64,
                backgroundColor: "",
                icon: sso.icon,
                display: sso.display,
            };
            return ((0, jsx_runtime_1.jsx)(antd_1.Col, { xs: 12, md: 6, children: (0, jsx_runtime_1.jsxs)(antd_1.Card, { size: "small", title: (0, jsx_runtime_1.jsx)(Text, { strong: true, children: sso.display }), extra: extra(sso), children: [(0, jsx_runtime_1.jsx)(Paragraph, { style: { textAlign: "center" }, children: (0, jsx_runtime_1.jsx)(sso_1.StrategyAvatar, { strategy: strategy, size: 64 }) }), (0, jsx_runtime_1.jsx)(Paragraph, { style: { textAlign: "center", marginBottom: 0 }, children: renderDomains(sso.domains) })] }) }, sso.id));
        });
    }
    function renderSSOList() {
        if (ssos.length === 0) {
            return ((0, jsx_runtime_1.jsx)(Text, { italic: true, type: "danger", children: "There are no 3rd party SSO providers available." }));
        }
        else {
            return ((0, jsx_runtime_1.jsx)(antd_1.Row, { gutter: [24, 24], align: "top", wrap: true, children: renderSSOs() }));
        }
    }
    function main() {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h1", { children: exports.SSO_SUBTITLE }), (0, jsx_runtime_1.jsxs)(Paragraph, { children: ["Sign up at ", customize.siteName, " via one of these 3", (0, jsx_runtime_1.jsx)("sup", { children: "rd" }), " party single sign-on mechanisms. You need to have an account at the respective organization in order to complete the sign-up process. Usually, this will be the only way you can sign up using your organization specific email address."] }), (0, jsx_runtime_1.jsx)(Paragraph, { children: renderSSOList() })] }));
    }
    return ((0, jsx_runtime_1.jsxs)(customize_1.Customize, { value: customize, children: [(0, jsx_runtime_1.jsx)(head_1.default, { title: exports.SSO_SUBTITLE }), (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: (0, sso_2.ssoNav)(), children: main() }), (0, jsx_runtime_1.jsx)(footer_1.default, {})] })] }));
}
exports.default = SignupIndex;
async function getServerSideProps(context) {
    const ssos = await (0, sso_3.getSSO)();
    return await (0, with_customize_1.default)({ context, props: { ssos } });
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=index.js.map