"use strict";
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = require("path");
var base_path_1 = __importDefault(require("lib/base-path"));
function editURL(options) {
    var type = options["type"];
    switch (type) {
        case "anonymous":
            return anonymousURL(options);
        case "collaborator":
        default:
            return collaboratorURL(options);
    }
}
exports.default = editURL;
// needed since we're making a link outside of the nextjs server.
function withBasePath(url) {
    return (0, path_1.join)(base_path_1.default, url);
}
function anonymousURL(_a) {
    var id = _a.id, path = _a.path, relativePath = _a.relativePath;
    var app = "/static/app.html";
    return withBasePath(encodeURI("".concat(app, "?anonymous=true&launch=share/").concat(id, "/").concat((0, path_1.join)(path, relativePath !== null && relativePath !== void 0 ? relativePath : ""))));
}
function collaboratorURL(_a) {
    var project_id = _a.project_id, path = _a.path, relativePath = _a.relativePath;
    var projectURL = (0, path_1.join)("/projects", project_id);
    if (!path) {
        return withBasePath(projectURL);
    }
    return withBasePath((0, path_1.join)(projectURL, "files", path, relativePath !== null && relativePath !== void 0 ? relativePath : ""));
}
//# sourceMappingURL=edit-url.js.map