"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");
/*
Edit some very basic configuration of a project, mainly that is relevant for sharing for now,
but maybe later everything.
*/
var react_1 = require("react");
var router_1 = require("next/router");
var antd_1 = require("antd");
var icon_1 = require("@cocalc/frontend/components/icon");
var edit_row_1 = __importDefault(require("components/misc/edit-row"));
var save_button_1 = __importDefault(require("components/misc/save-button"));
function Edit(props) {
    var router = (0, router_1.useRouter)();
    var _a = __read((0, react_1.useState)(!!router.query.edit), 2), expanded = _a[0], setExpanded = _a[1];
    return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: { marginBottom: "15px" } }, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Button, __assign({ disabled: expanded, onClick: function (e) {
                    e.preventDefault();
                    setExpanded(true);
                }, size: "small" }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "pencil" }), " Edit..."] }), "edit"), expanded && ((0, jsx_runtime_1.jsx)(EditFields, { info: props, onClose: function () {
                    setExpanded(false);
                    // This reloads the page, but with no flicker, so user sees new information reflected.
                    router.push({ pathname: router.asPath.split("?")[0] });
                } }))] })));
}
exports.default = Edit;
function EditFields(_a) {
    var info = _a.info, onClose = _a.onClose;
    var _b = __read((0, react_1.useState)(info), 2), edited = _b[0], setEdited = _b[1];
    var _c = __read((0, react_1.useState)(info), 2), original = _c[0], setOriginal = _c[1];
    return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: {
            width: "100%",
            border: "1px solid #eee",
            padding: "15px",
            marginTop: "15px",
        } }, { children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)(antd_1.Space, __assign({ style: { float: "right" } }, { children: [(0, jsx_runtime_1.jsx)(save_button_1.default, { edited: edited, original: original, setOriginal: setOriginal, table: "projects" }), (0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ style: { float: "right" }, onClick: onClose }, { children: "Close" }))] })) }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)(edit_row_1.default, __assign({ label: "Title" }, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { value: edited.title, onChange: function (e) { return setEdited(__assign(__assign({}, edited), { title: e.target.value })); } }) })), (0, jsx_runtime_1.jsx)(edit_row_1.default, __assign({ label: "Description" }, { children: (0, jsx_runtime_1.jsx)(antd_1.Input.TextArea, { value: edited.description, onChange: function (e) {
                        return setEdited(__assign(__assign({}, edited), { description: e.target.value }));
                    }, autoSize: { minRows: 2 } }) })), (0, jsx_runtime_1.jsx)(edit_row_1.default, __assign({ label: "Name (for nicer URLs)" }, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { value: edited.name, onChange: function (e) { return setEdited(__assign(__assign({}, edited), { name: e.target.value })); } }) }))] })));
}
//# sourceMappingURL=edit.js.map