"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 server_settings_1 = require("@cocalc/server/settings/server-settings");
const pool_1 = __importStar(require("@cocalc/database/pool"));
const antd_1 = require("antd");
const path_1 = __importDefault(require("components/app/path"));
const content_1 = __importDefault(require("components/landing/content"));
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 logo_square_1 = __importDefault(require("components/logo-square"));
const A_1 = __importDefault(require("components/misc/A"));
const proxy_input_1 = __importDefault(require("components/share/proxy-input"));
const public_paths_1 = __importDefault(require("components/share/public-paths"));
const get_account_1 = __importDefault(require("lib/account/get-account"));
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 path_2 = require("path");
const cocalc_screenshot_20200128_nq8_png_1 = __importDefault(require("public/cocalc-screenshot-20200128-nq8.png"));
const topLinkStyle = { marginRight: "20px" };
function Home(props) {
    const { customize, publicPaths } = props;
    const { shareServer, siteName, siteDescription, organizationName, organizationURL, splashImage, indexInfo, sandboxProjectId, onCoCalcCom, } = customize;
    function renderAboveImage() {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [sandboxProjectId && ((0, jsx_runtime_1.jsxs)("div", { style: { marginBottom: "30px" }, children: [(0, jsx_runtime_1.jsxs)("h3", { style: { textAlign: "center", color: "#666" }, children: ["The Public ", siteName, " Sandbox"] }), (0, jsx_runtime_1.jsx)(path_1.default, { style: { marginRight: "15px", marginBottom: "15px" }, project_id: sandboxProjectId, description: "Public Sandbox" })] })), shareServer && onCoCalcCom && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h3", { style: { textAlign: "center" }, children: (0, jsx_runtime_1.jsxs)(A_1.default, { href: "/share/public_paths/page/1", children: ["Explore what people have shared using ", siteName, "!"] }) }), publicPaths && ((0, jsx_runtime_1.jsxs)("div", { style: {
                                maxHeight: "60vh",
                                overflow: "auto",
                                marginRight: "15px",
                            }, children: [(0, jsx_runtime_1.jsx)(proxy_input_1.default, {}), (0, jsx_runtime_1.jsx)(public_paths_1.default, { publicPaths: publicPaths })] }))] }))] }));
    }
    return ((0, jsx_runtime_1.jsxs)(customize_1.Customize, { value: customize, children: [(0, jsx_runtime_1.jsx)(head_1.default, { title: "Collaborative Calculation" }), (0, jsx_runtime_1.jsxs)(antd_1.Layout, { children: [(0, jsx_runtime_1.jsx)(header_1.default, {}), (0, jsx_runtime_1.jsxs)(antd_1.Layout.Content, { style: { backgroundColor: "white" }, children: [customize.account && ((0, jsx_runtime_1.jsxs)("div", { style: {
                                    textAlign: "center",
                                    margin: "30px 0 -15px 0",
                                    color: "#666",
                                    fontSize: "30pt",
                                    fontWeight: 500,
                                }, children: ["Signed in as", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/config", children: `${customize.account.first_name} ${customize.account.last_name} ${customize.account.name
                                            ? "(@" + customize.account.name + ")"
                                            : ""}` }), (0, jsx_runtime_1.jsxs)("div", { style: { fontSize: "11pt", margin: "15px 0" }, children: [customize.isCommercial &&
                                                customize.account &&
                                                !customize.account.is_anonymous && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, { href: "/store", style: topLinkStyle, children: "Store" }), " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/licenses", style: topLinkStyle, children: "Licenses" }), " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/billing", style: topLinkStyle, children: "Billing" }), " "] })), customize.account != null && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, { href: (0, path_2.join)(base_path_1.default, "projects"), external: true, style: topLinkStyle, children: "Projects" }), " "] })), customize.landingPages && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, { href: "/features/", style: topLinkStyle, children: "Features" }), " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/software", style: topLinkStyle, children: "Software" }), " ", customize.isCommercial && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, { href: "/pricing", style: topLinkStyle, children: "Pricing" }), " "] }))] })), customize.account != null && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, { href: "/config", style: topLinkStyle, children: "Config" }), " "] })), customize.shareServer && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, { style: topLinkStyle, href: "/share/public_paths/page/1", children: "Share" }), " "] })), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, { style: topLinkStyle, href: "/support", children: "Support" }), " ", (0, jsx_runtime_1.jsx)(A_1.default, { style: topLinkStyle, href: "/info", children: "Docs" })] })] })] })), (0, jsx_runtime_1.jsx)(content_1.default, { logo: (0, jsx_runtime_1.jsx)(logo_square_1.default, { style: { width: "120px", height: "120px" } }), title: siteName, subtitle: siteDescription, description: (0, jsx_runtime_1.jsxs)("div", { children: ["An instance of ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "https://cocalc.com", children: "CoCalc" }), " ", organizationName && organizationURL && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["hosted by ", (0, jsx_runtime_1.jsx)(A_1.default, { href: organizationURL, children: organizationName })] })), onCoCalcCom && ((0, jsx_runtime_1.jsxs)("div", { style: { marginTop: "15px" }, children: [(0, jsx_runtime_1.jsx)(A_1.default, { href: "https://about.cocalc.com", children: "Mission and Features of CoCalc" }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("iframe", { width: "210", height: "300", src: "https://www.youtube.com/embed/PQ5p92DN0bs", title: "YouTube video player", frameBorder: 0, allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture", allowFullScreen: true }), (0, jsx_runtime_1.jsx)("br", {})] }))] }), image: sandboxProjectId
                                    ? undefined
                                    : splashImage
                                        ? splashImage
                                        : cocalc_screenshot_20200128_nq8_png_1.default, aboveImage: renderAboveImage(), alt: "Screenshot showing CoCalc in action!", indexInfo: indexInfo }), (0, jsx_runtime_1.jsx)(footer_1.default, {})] })] })] }));
}
exports.default = Home;
async function getServerSideProps(context) {
    const isAuthenticated = (await (0, get_account_1.default)(context.req)) != null;
    const pool = (0, pool_1.default)("long");
    const { share_server } = await (0, server_settings_1.getServerSettings)();
    let publicPaths;
    if (share_server) {
        const { rows } = await pool.query(`SELECT id, path, url, description, ${(0, pool_1.timeInSeconds)("last_edited")},
    counter::INT,
     (SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=id) AS stars
    FROM public_paths
    WHERE vhost IS NULL AND disabled IS NOT TRUE AND unlisted IS NOT TRUE AND
    ((authenticated IS TRUE AND $1 IS TRUE) OR (authenticated IS NOT TRUE))
    ORDER BY stars DESC,last_edited DESC LIMIT $2`, [isAuthenticated, 150]);
        publicPaths = rows;
    }
    else {
        publicPaths = null;
    }
    return await (0, with_customize_1.default)({ context, props: { publicPaths } }, { name: true });
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=index.js.map