"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");
/*
Very bad experimental first account name configuration page.
This is extremely preliminary and just for experimentation.
*/
var react_1 = require("react");
var antd_1 = require("antd");
var loading_1 = __importDefault(require("components/share/loading"));
var database_1 = __importDefault(require("lib/hooks/database"));
var save_button_1 = __importDefault(require("components/misc/save-button"));
var A_1 = __importDefault(require("components/misc/A"));
var register_1 = __importDefault(require("../register"));
var icon_1 = require("@cocalc/frontend/components/icon");
var firstNameDesc = "Your name is used for interacting with\nother users in chat, your cursor when editing, etc. The first\nletter of your first name is used for your avatar if you do not\nupload an image.";
var lastNameDesc = "Your full name is used to label your cursor\nwhen you edit collaboratively with other people, and to identify\nyou when you are @mentioned.   CoCalc does NOT have\na policy that you must user your real name, and you can change your\nname at any time.";
var unlistedDesc = "By default both your name and exact email address are\nused when people search to add users as collaborators to projects.  There is\nno way to do a search for partial email addresses, and your email address\nis never revealed to other users.   If you choose to be unlisted, then you can\nonly be added as a collaborator to a project by an exact email\naddress match.";
(0, register_1.default)({
    path: "account/name",
    title: "Your Name",
    icon: "user-times",
    desc: "Configure your first name, last name, username and whether or not your account is unlisted.",
    search: "{firstNameDesc} {lastNameDesc} Your username provides a nice URL for content you share publicly. unlisted {unlistedDesc}\"",
    Component: ConfigureName,
});
function ConfigureName() {
    var get = (0, database_1.default)({
        accounts: {
            first_name: null,
            last_name: null,
            name: null,
            unlisted: null,
        },
    });
    var _a = __read((0, react_1.useState)(undefined), 2), original = _a[0], setOriginal = _a[1];
    var _b = __read((0, react_1.useState)(undefined), 2), edited = _b[0], setEdited = _b[1];
    (0, react_1.useEffect)(function () {
        if (!get.loading && original === undefined && get.value.accounts != null) {
            setOriginal(get.value.accounts);
            setEdited(get.value.accounts);
        }
    }, [get.loading]);
    function onChange(field, value) {
        if (value === void 0) { value = "value"; }
        return function (e) {
            var _a;
            return setEdited(__assign(__assign({}, edited), (_a = {}, _a[field] = e.target[value], _a)));
        };
    }
    if (original == null || edited == null) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, {});
    }
    return ((0, jsx_runtime_1.jsxs)("div", { children: [get.error && ((0, jsx_runtime_1.jsx)(antd_1.Alert, { style: { marginTop: "20px" }, message: "Error loading data", description: get.error, type: "error", showIcon: true })), " ", get.loading ? ((0, jsx_runtime_1.jsx)(loading_1.default, {})) : ((0, jsx_runtime_1.jsx)("form", { children: (0, jsx_runtime_1.jsxs)(antd_1.Space, __assign({ direction: "vertical", style: { width: "100%", maxWidth: "500px" } }, { children: [(0, jsx_runtime_1.jsx)(save_button_1.default, { edited: edited, original: original, setOriginal: setOriginal, table: "accounts" }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("b", { children: "First Name" }), " ", firstNameDesc, (0, jsx_runtime_1.jsx)(antd_1.Input, { addonBefore: "First name", defaultValue: get.value.accounts.first_name, onChange: onChange("first_name") }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("b", { children: "Last Name" }), " ", lastNameDesc, (0, jsx_runtime_1.jsx)(antd_1.Input, { addonBefore: "Last name", defaultValue: get.value.accounts.last_name, onChange: onChange("last_name") }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("b", { children: "Username" }), (0, jsx_runtime_1.jsxs)("div", { children: ["Your username provides a", " ", edited.name ? ((0, jsx_runtime_1.jsx)(A_1.default, __assign({ external: true, href: "/".concat(edited.name) }, { children: "nice URL" }))) : ("nice URL"), " ", "for content you share publicly.", original.name && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [" ", "(Changing your name could break links that you have shared.)"] }))] }), (0, jsx_runtime_1.jsx)(antd_1.Input, { addonBefore: "Name", defaultValue: get.value.accounts.name, onChange: onChange("name") }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsxs)("b", { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "user-secret" }), " Unlisted"] }), (0, jsx_runtime_1.jsx)("div", { children: unlistedDesc }), (0, jsx_runtime_1.jsx)(antd_1.Checkbox, __assign({ defaultChecked: get.value.accounts.unlisted, onChange: onChange("unlisted", "checked") }, { children: "Unlisted" }))] })) }))] }));
}
//# sourceMappingURL=name.js.map