"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
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 given project

Show all the public paths in a given project, and maybe other information about the project?
*/
const react_1 = require("react");
const router_1 = require("next/router");
const public_paths_1 = __importDefault(require("components/share/public-paths"));
const collaborators_1 = __importDefault(require("components/share/collaborators"));
const loading_1 = __importDefault(require("components/share/loading"));
const layout_1 = require("components/share/layout");
const A_1 = __importDefault(require("components/misc/A"));
const customize_1 = require("lib/share/customize");
const edit_1 = __importDefault(require("./edit"));
const edit_url_1 = __importDefault(require("lib/share/edit-url"));
const static_markdown_1 = __importDefault(require("@cocalc/frontend/editors/slate/static-markdown"));
const antd_1 = require("antd");
function Project({ project_id, publicPaths, collaborators, title, description, name, customize, avatar_image_full, redirect, }) {
    const router = (0, router_1.useRouter)();
    (0, react_1.useEffect)(() => {
        if (redirect) {
            router.push(redirect);
        }
    }, [redirect]);
    if (publicPaths == null || collaborators == null || title == null) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, { style: { fontSize: "30px" } });
    }
    const collab = isCollaborator(customize.account, collaborators);
    return ((0, jsx_runtime_1.jsx)(customize_1.Customize, { value: customize, children: (0, jsx_runtime_1.jsxs)(layout_1.Layout, { title: title, children: [(0, jsx_runtime_1.jsxs)("h1", { children: [avatar_image_full && ((0, jsx_runtime_1.jsx)(antd_1.Avatar, { icon: (0, jsx_runtime_1.jsx)("img", { src: avatar_image_full }), size: 160, shape: "square", style: { float: "right" } })), "Project:", " ", collab ? ((0, jsx_runtime_1.jsx)(A_1.default, { href: (0, edit_url_1.default)({ project_id, type: "collaborator" }), external: true, children: title })) : (title)] }), (0, jsx_runtime_1.jsx)("div", { style: { color: "#666" }, children: (0, jsx_runtime_1.jsx)(static_markdown_1.default, { value: description }) }), collab && ((0, jsx_runtime_1.jsx)(edit_1.default, { project_id: project_id, title: title, description: description, name: name })), collaborators != null && collaborators.length > 0 && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h2", { children: "Collaborators" }), (0, jsx_runtime_1.jsx)(collaborators_1.default, { collaborators: collaborators }), (0, jsx_runtime_1.jsx)("br", {}), " ", (0, jsx_runtime_1.jsx)("br", {})] })), (0, jsx_runtime_1.jsx)("h2", { children: "Public Paths" }), collab && ((0, jsx_runtime_1.jsx)("div", { style: { marginBottom: "15px" }, children: "You are a collaborator on this project, so unlisted and disabled public paths are also listed here, so you can more easily edit them." })), publicPaths != null && publicPaths.length == 0 ? ((0, jsx_runtime_1.jsx)("div", { children: "No public paths." })) : ((0, jsx_runtime_1.jsx)(public_paths_1.default, { publicPaths: publicPaths }))] }) }));
}
exports.default = Project;
function isCollaborator(account, collaborators) {
    const account_id = account?.account_id;
    if (account_id == null)
        return false;
    for (const user of collaborators) {
        if (user.account_id == account_id)
            return true;
    }
    return false;
}
//# sourceMappingURL=project.js.map