"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");
const antd_1 = require("antd");
const icon_1 = require("@cocalc/frontend/components/icon");
const post_1 = __importDefault(require("lib/api/post"));
const router_1 = require("next/router");
const A_1 = __importDefault(require("components/misc/A"));
const react_1 = require("react");
const use_customize_1 = __importDefault(require("lib/use-customize"));
const database_1 = __importDefault(require("lib/hooks/database"));
const loading_1 = __importDefault(require("components/share/loading"));
const register_1 = __importDefault(require("../register"));
(0, register_1.default)({
    path: "account/delete",
    title: "Delete Account",
    icon: "trash",
    desc: "Delete your account.",
    danger: true,
    Component: () => {
        const { loading, value } = (0, database_1.default)({
            accounts: { first_name: null, last_name: null },
        });
        const { siteName } = (0, use_customize_1.default)();
        const [name, setName] = (0, react_1.useState)("");
        const [fullName, setFullName] = (0, react_1.useState)("");
        const [error, setError] = (0, react_1.useState)("");
        const [deleting, setDeleting] = (0, react_1.useState)(false);
        const router = (0, router_1.useRouter)();
        (0, react_1.useEffect)(() => {
            if (!loading) {
                setFullName((value.accounts.first_name + " " + value.accounts.last_name).trim());
            }
        }, [loading]);
        if (loading) {
            return (0, jsx_runtime_1.jsx)(loading_1.default, {});
        }
        return ((0, jsx_runtime_1.jsxs)(antd_1.Space, { direction: "vertical", children: [(0, jsx_runtime_1.jsxs)("h2", { children: ["Are you sure you want to ", (0, jsx_runtime_1.jsxs)("b", { children: ["delete your ", siteName, " account"] }), "?"] }), (0, jsx_runtime_1.jsxs)("p", { children: ["You will immediately lose access to all of", " ", (0, jsx_runtime_1.jsx)(A_1.default, { external: true, href: "/projects", children: "your projects" }), ", and any purchased subscriptions will be canceled."] }), (0, jsx_runtime_1.jsxs)("p", { children: ["Do NOT delete your account if you are", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "https://github.com/sagemathinc/cocalc/issues/3243", children: "a current student in a course..." })] }), (0, jsx_runtime_1.jsxs)("p", { children: ["To ", (0, jsx_runtime_1.jsx)("b", { children: "DELETE YOUR ACCOUNT" }), ", first type your full name \"", fullName, "\" below (without quotes):", (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)(antd_1.Input, { style: { marginTop: "15px", maxWidth: `${2 * fullName.length}ex` }, placeholder: "Type your full name here...", onChange: (e) => setName(e.target.value), onPaste: (e) => {
                                e.preventDefault();
                                return false;
                            } })] }), (0, jsx_runtime_1.jsxs)(antd_1.Button, { disabled: name != fullName || deleting, type: "primary", danger: true, onClick: async () => {
                        try {
                            setError("");
                            setDeleting(true);
                            await (0, post_1.default)("/accounts/delete");
                            router.push("/");
                        }
                        catch (err) {
                            setError(err.message);
                        }
                        finally {
                            setDeleting(false);
                        }
                    }, children: [deleting && (0, jsx_runtime_1.jsx)(loading_1.default, { children: "Deleting Your Account..." }), !deleting && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "trash" }), " Permanently Delete My ", siteName, " Account", name != fullName && (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "\u00A0(type your full name above)" })] }))] }), (0, jsx_runtime_1.jsx)("br", {}), error && (0, jsx_runtime_1.jsx)(antd_1.Alert, { type: "error", message: error, showIcon: true })] }));
    },
});
//# sourceMappingURL=delete-account.js.map