"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 © 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 (?).

*/
const icon_1 = require("@cocalc/frontend/components/icon");
const antd_1 = require("antd");
const router_1 = require("next/router");
const react_1 = require("react");
const edit_options_1 = __importDefault(require("./edit-options"));
function Edit({ id, path, url, relativePath, project_id, image, description, }) {
    const router = (0, router_1.useRouter)();
    const [expanded, setExpanded] = (0, react_1.useState)(!!router.query.edit);
    (0, react_1.useEffect)(() => {
        setExpanded(!!router.query.edit);
    }, [id, path, url, relativePath]);
    return ((0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsxs)(antd_1.Button, { disabled: expanded, onClick: (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: () => {
                    setExpanded(false);
                } }))] }));
}
exports.default = Edit;
//# sourceMappingURL=index.js.map