"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 __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
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
 */
/*
When you want to edit an existing public share, here's the flow of what happens.

- If you are a collaborator on the project with the shared document it shows a button to "Open the file in my project" (or something).
- If you are NOT a collaborator on the project there are various states:
  - If you are NOT signed in it gives you the option to:
    - Sign in, then start this flowchart over
    - Sign up, then start this over
    - Create a new anonymous project and anonymously edit this content.
  - If you are signed in, it gives you these options:
    - Create a new project and copy this content to that project (and it opens the project in a new tab).
    - Copy this content to one of your existing projects.
      - If you select this, then a select an existing projects, and maybe a directory in that project.
      - Project starts and content gets copied
      - Maybe when done get a link and can open that.
- In all cases above, if share comes with a license (i.e., the CUP situation), then that license gets applied to the relevant project... temporarily (?).

*/
var react_1 = require("react");
var antd_1 = require("antd");
var icon_1 = require("@cocalc/frontend/components/icon");
var router_1 = require("next/router");
var edit_options_1 = __importDefault(require("./edit-options"));
function Edit(_a) {
    var id = _a.id, path = _a.path, url = _a.url, relativePath = _a.relativePath, project_id = _a.project_id, image = _a.image, description = _a.description;
    var router = (0, router_1.useRouter)();
    var _b = __read((0, react_1.useState)(!!router.query.edit), 2), expanded = _b[0], setExpanded = _b[1];
    (0, react_1.useEffect)(function () {
        setExpanded(!!router.query.edit);
    }, [id, path, url, relativePath]);
    return ((0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsxs)(antd_1.Button, __assign({ disabled: expanded, onClick: function (e) {
                    e.preventDefault();
                    setExpanded(true);
                } }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "pencil" }), " Edit..."] }), "edit"), expanded && ((0, jsx_runtime_1.jsx)(edit_options_1.default, { id: id, path: path, url: url, relativePath: relativePath, project_id: project_id, image: image, description: description, onClose: function () {
                    setExpanded(false);
                } }))] }));
}
exports.default = Edit;
//# sourceMappingURL=index.js.map