"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 __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
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
 */
/*
Page for a given project

Show all the public paths in a given project, and maybe other information about the project?
*/
var public_paths_1 = __importDefault(require("components/share/public-paths"));
var collaborators_1 = __importDefault(require("components/share/collaborators"));
var loading_1 = __importDefault(require("components/share/loading"));
var layout_1 = require("components/share/layout");
var A_1 = __importDefault(require("components/misc/A"));
var customize_1 = require("lib/share/customize");
var edit_1 = __importDefault(require("./edit"));
var edit_url_1 = __importDefault(require("lib/share/edit-url"));
var static_markdown_1 = __importDefault(require("@cocalc/frontend/editors/slate/static-markdown"));
function Project(_a) {
    var project_id = _a.project_id, publicPaths = _a.publicPaths, collaborators = _a.collaborators, title = _a.title, description = _a.description, name = _a.name, customize = _a.customize;
    if (publicPaths == null || collaborators == null || title == null) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, { style: { fontSize: "30px" } });
    }
    var collab = isCollaborator(customize.account, collaborators);
    return ((0, jsx_runtime_1.jsx)(customize_1.Customize, __assign({ value: customize }, { children: (0, jsx_runtime_1.jsxs)(layout_1.Layout, __assign({ title: title }, { children: [(0, jsx_runtime_1.jsxs)("h1", { children: ["Project:", " ", collab ? ((0, jsx_runtime_1.jsx)(A_1.default, __assign({ href: (0, edit_url_1.default)({ project_id: project_id, type: "collaborator" }), external: true }, { children: title }))) : (title)] }), (0, jsx_runtime_1.jsx)("div", __assign({ 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", __assign({ 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) {
    var e_1, _a;
    var account_id = account === null || account === void 0 ? void 0 : account.account_id;
    if (account_id == null)
        return false;
    try {
        for (var collaborators_2 = __values(collaborators), collaborators_2_1 = collaborators_2.next(); !collaborators_2_1.done; collaborators_2_1 = collaborators_2.next()) {
            var user = collaborators_2_1.value;
            if (user.account_id == account_id)
                return true;
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (collaborators_2_1 && !collaborators_2_1.done && (_a = collaborators_2.return)) _a.call(collaborators_2);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return false;
}
//# sourceMappingURL=project.js.map