"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getServerSideProps = void 0;
var 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
 */
var antd_1 = require("antd");
var footer_1 = __importDefault(require("components/landing/footer"));
var A_1 = __importDefault(require("components/misc/A"));
var logo_square_1 = __importDefault(require("components/logo-square"));
var header_1 = __importDefault(require("components/landing/header"));
var content_1 = __importDefault(require("components/landing/content"));
var with_customize_1 = __importDefault(require("lib/with-customize"));
var customize_1 = require("lib/customize");
var head_1 = __importDefault(require("components/landing/head"));
var path_1 = require("path");
var base_path_1 = __importDefault(require("lib/base-path"));
var cocalc_screenshot_20200128_nq8_png_1 = __importDefault(require("public/cocalc-screenshot-20200128-nq8.png"));
var path_2 = __importDefault(require("components/app/path"));
var public_paths_1 = __importDefault(require("components/share/public-paths"));
var get_account_1 = __importDefault(require("lib/account/get-account"));
var pool_1 = __importStar(require("@cocalc/database/pool"));
var topLinkStyle = { marginRight: "20px" };
function Home(_a) {
    var customize = _a.customize, publicPaths = _a.publicPaths;
    var shareServer = customize.shareServer, siteName = customize.siteName, siteDescription = customize.siteDescription, organizationName = customize.organizationName, organizationURL = customize.organizationURL, splashImage = customize.splashImage, indexInfo = customize.indexInfo, sandboxProjectId = customize.sandboxProjectId;
    return ((0, jsx_runtime_1.jsxs)(customize_1.Customize, __assign({ 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, __assign({ style: { backgroundColor: "white" } }, { children: [customize.account && ((0, jsx_runtime_1.jsxs)("div", __assign({ 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, __assign({ href: "/config" }, { children: "".concat(customize.account.first_name, " ").concat(customize.account.last_name, " ").concat(customize.account.name
                                            ? "(@" + customize.account.name + ")"
                                            : "") })), (0, jsx_runtime_1.jsxs)("div", __assign({ style: { fontSize: "10pt", margin: "15px 0" } }, { children: [customize.account != null && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, __assign({ href: (0, path_1.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, __assign({ href: "/features/", style: topLinkStyle }, { children: "Features" })), " ", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ 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, __assign({ 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, __assign({ href: "/config", style: topLinkStyle }, { children: "Config" })), " "] })), 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, __assign({ href: "/store", style: topLinkStyle }, { children: "Store" })), " ", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ href: "/licenses", style: topLinkStyle }, { children: "Licenses" })), " ", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ href: "/billing", style: topLinkStyle }, { children: "Billing" })), " "] })), customize.shareServer && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(A_1.default, __assign({ 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, __assign({ style: topLinkStyle, href: "/support" }, { children: "Support" })), " ", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ style: topLinkStyle, href: "/info/status" }, { children: "Status" })), " ", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ style: topLinkStyle, href: "https://doc.cocalc.com" }, { 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, __assign({ 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, __assign({ href: organizationURL }, { children: organizationName }))] })), customize.onCoCalcCom && ((0, jsx_runtime_1.jsxs)("div", __assign({ style: { marginTop: "15px" } }, { children: [(0, jsx_runtime_1.jsx)(A_1.default, __assign({ 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: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [sandboxProjectId && ((0, jsx_runtime_1.jsxs)("div", __assign({ style: { marginBottom: "30px" } }, { children: [(0, jsx_runtime_1.jsxs)("h3", __assign({ style: { textAlign: "center", color: "#666" } }, { children: ["The Public ", siteName, " Sandbox"] })), (0, jsx_runtime_1.jsx)(path_2.default, { style: { marginRight: "15px", marginBottom: "15px" }, project_id: sandboxProjectId, description: "Public Sandbox" })] }))), shareServer && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h3", __assign({ style: { textAlign: "center" } }, { children: (0, jsx_runtime_1.jsxs)(A_1.default, __assign({ href: "/share/public_paths/page/1" }, { children: ["Explore what people have shared using ", siteName, "!"] })) })), publicPaths && ((0, jsx_runtime_1.jsx)("div", __assign({ style: { maxHeight: "60vh", overflow: "auto", marginRight: '15px' } }, { children: (0, jsx_runtime_1.jsx)(public_paths_1.default, { publicPaths: publicPaths }) })))] }))] }), alt: "Screenshot showing CoCalc in action!", indexInfo: indexInfo }), (0, jsx_runtime_1.jsx)(footer_1.default, {})] }))] })] })));
}
exports.default = Home;
function getServerSideProps(context) {
    return __awaiter(this, void 0, void 0, function () {
        var isAuthenticated, pool, rows, publicPaths, rows_1;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, (0, get_account_1.default)(context.req)];
                case 1:
                    isAuthenticated = (_a.sent()) != null;
                    pool = (0, pool_1.default)("long");
                    return [4 /*yield*/, pool.query("select value from server_settings where name='share_server'")];
                case 2:
                    rows = (_a.sent()).rows;
                    if (!(rows.length > 0 && rows[0].value == "yes")) return [3 /*break*/, 4];
                    return [4 /*yield*/, pool.query("SELECT id, path, description, ".concat((0, pool_1.timeInSeconds)("last_edited"), ",\n    counter::INT,\n     (SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=id) AS stars\n    FROM public_paths\n    WHERE vhost IS NULL AND disabled IS NOT TRUE AND unlisted IS NOT TRUE AND\n    ((authenticated IS TRUE AND $1 IS TRUE) OR (authenticated IS NOT TRUE))\n    ORDER BY last_edited DESC LIMIT $2"), [isAuthenticated, 150])];
                case 3:
                    rows_1 = (_a.sent()).rows;
                    publicPaths = rows_1;
                    return [3 /*break*/, 5];
                case 4:
                    publicPaths = null;
                    _a.label = 5;
                case 5: return [4 /*yield*/, (0, with_customize_1.default)({ context: context, props: { publicPaths: publicPaths } }, { name: true })];
                case 6: return [2 /*return*/, _a.sent()];
            }
        });
    });
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=index.js.map