"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
 */
// Page for a project that is owned by a named account
// or organization.
const project_1 = __importDefault(require("lib/names/project"));
const with_customize_1 = __importDefault(require("lib/with-customize"));
const info_1 = __importDefault(require("lib/project/info"));
const get_project_1 = __importDefault(require("lib/share/get-project"));
const project_2 = __importDefault(require("components/project/project"));
const organization_1 = __importDefault(require("components/share/proxy/organization"));
const get_public_path_info_github_1 = __importDefault(require("lib/share/proxy/get-public-path-info-github"));
function Page(props) {
    if (props.project_id) {
        return (0, jsx_runtime_1.jsx)(project_2.default, { ...props });
    }
    else {
        // e.g., for listing all github repos in an org:
        return (0, jsx_runtime_1.jsx)(organization_1.default, { ...props });
    }
}
exports.default = Page;
async function getServerSideProps(context) {
    const { owner, project } = context.params;
    try {
        let props;
        if (owner == "github") {
            // special case for special github URL's
            // This is a URL like   https://cocalc.com/github/cocalc,
            // which will end up listing all public repos under the cocalc org (say).
            props = {
                ...(await (0, get_public_path_info_github_1.default)(`${owner}/${project}`)),
                organization: project,
            };
        }
        else {
            const project_id = await (0, project_1.default)(owner, project);
            props = {
                project_id,
                ...(await (0, info_1.default)(project_id, context.req)),
                ...(await (0, get_project_1.default)(project_id, [
                    "name",
                    "title",
                    "description",
                    "avatar_image_full",
                ])),
            };
        }
        return (0, with_customize_1.default)({ context, props });
    }
    catch (err) {
        console.log(err);
        return { notFound: true };
    }
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=%5Bproject%5D.js.map