"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 __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 © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var antd_1 = require("antd");
var link_1 = __importDefault(require("next/link"));
var path_contents_1 = __importDefault(require("components/share/path-contents"));
var path_actions_1 = __importDefault(require("components/share/path-actions"));
var linked_path_1 = __importDefault(require("components/share/linked-path"));
var loading_1 = __importDefault(require("components/share/loading"));
var license_1 = __importDefault(require("components/share/license"));
var project_link_1 = __importDefault(require("components/share/project-link"));
var counter_1 = __importDefault(require("lib/share/counter"));
var layout_1 = require("components/share/layout");
var customize_1 = require("lib/share/customize");
var util_1 = require("lib/share/util");
var sanitized_markdown_1 = __importDefault(require("components/misc/sanitized-markdown"));
var icon_1 = require("@cocalc/frontend/components/icon");
var ui_1 = require("@cocalc/util/consts/ui");
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
function PublicPath(props) {
    var id = props.id, path = props.path, project_id = props.project_id, projectTitle = props.projectTitle, relativePath = props.relativePath, description = props.description, counter = props.counter, compute_image = props.compute_image, license = props.license, contents = props.contents, error = props.error, customize = props.customize, disabled = props.disabled, unlisted = props.unlisted, authenticated = props.authenticated;
    (0, counter_1.default)(id);
    if (id == null)
        return (0, jsx_runtime_1.jsx)(loading_1.default, { style: { fontSize: "30px" } });
    if (error != null) {
        return ((0, jsx_runtime_1.jsxs)("div", { children: ["There was a problem loading \"", relativePath, "\" in", " ", (0, jsx_runtime_1.jsx)(link_1.default, __assign({ href: "/share/public_paths/".concat(id) }, { children: (0, jsx_runtime_1.jsxs)("a", { children: [path, "."] }) })), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("br", {}), error] }));
    }
    function visibility_explanation() {
        if (disabled) {
            return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "lock" }), " Private (only visible to collaborators on the project)"] }));
        }
        if (unlisted) {
            return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "eye-slash" }), " Unlisted (only visible to those who know the link)"] }));
        }
        if (authenticated) {
            return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: ui_1.SHARE_AUTHENTICATED_ICON }), " Authenticated (", ui_1.SHARE_AUTHENTICATED_EXPLANATION, ")"] }));
        }
    }
    function visibility() {
        if (unlisted || disabled || authenticated) {
            return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("b", { children: "Visibility:" }), " ", visibility_explanation()] }));
        }
    }
    return ((0, jsx_runtime_1.jsx)(customize_1.Customize, __assign({ value: customize }, { children: (0, jsx_runtime_1.jsxs)(layout_1.Layout, __assign({ title: (0, util_1.getTitle)({ path: path, relativePath: relativePath }) }, { children: [(0, jsx_runtime_1.jsx)("b", { children: "Path: " }), (0, jsx_runtime_1.jsx)(linked_path_1.default, { path: path, relativePath: relativePath, id: id, isDir: contents === null || contents === void 0 ? void 0 : contents.isdir }), (0, jsx_runtime_1.jsx)("br", {}), (description === null || description === void 0 ? void 0 : description.trim()) && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("b", { children: "Description:" }), " ", (0, jsx_runtime_1.jsx)(sanitized_markdown_1.default, { value: description })] })), counter && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("b", { children: "Views:" }), " ", counter, (0, jsx_runtime_1.jsx)("br", {})] })), (0, jsx_runtime_1.jsx)("b", { children: "License:" }), " ", (0, jsx_runtime_1.jsx)(license_1.default, { license: license }), (0, jsx_runtime_1.jsx)("br", {}), visibility(), compute_image && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("b", { children: "Image:" }), " ", compute_image, (0, jsx_runtime_1.jsx)("br", {})] })), (0, jsx_runtime_1.jsx)("b", { children: "Project:" }), " ", (0, jsx_runtime_1.jsx)(project_link_1.default, { project_id: project_id, title: projectTitle }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)(path_actions_1.default, { id: id, path: path, relativePath: relativePath, isDir: contents === null || contents === void 0 ? void 0 : contents.isdir, exclude: new Set(["hosted"]), project_id: project_id, image: compute_image, description: description }), (0, jsx_runtime_1.jsx)(antd_1.Divider, {}), contents != null && ((0, jsx_runtime_1.jsx)(path_contents_1.default, __assign({ id: id, relativePath: relativePath, path: path }, contents)))] })) })));
}
exports.default = PublicPath;
//# sourceMappingURL=path.js.map