"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 post_1 = __importDefault(require("lib/api/post"));
const react_1 = require("react");
const icon_1 = require("@cocalc/frontend/components/icon");
const antd_1 = require("antd");
const logo_square_1 = __importDefault(require("components/logo-square"));
const shared_1 = require("./shared");
const contact_1 = __importDefault(require("components/landing/contact"));
function RedeemVerifyEmail({ token, email_address }) {
    const [redeeming, setRedeeming] = (0, react_1.useState)(false);
    const [error, setError] = (0, react_1.useState)("");
    const [success, setSuccess] = (0, react_1.useState)("");
    async function redeem() {
        setRedeeming(true);
        setError("");
        setSuccess("");
        try {
            await (0, post_1.default)("/auth/redeem-verify-email", {
                email_address,
                token,
            });
            setSuccess("Successfully verified your email address. Thanks!");
        }
        catch (err) {
            setError(`${err}`);
        }
        finally {
            setRedeeming(false);
        }
    }
    (0, react_1.useEffect)(() => {
        redeem();
        return;
    }, []);
    function Body() {
        if (redeeming) {
            return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "spinner", spin: true }), " Verifying your email address..."] }));
        }
        return ((0, jsx_runtime_1.jsxs)("div", { children: [error && ((0, jsx_runtime_1.jsx)(antd_1.Alert, { style: { marginTop: "20px" }, message: "Error", description: (0, jsx_runtime_1.jsxs)("div", { style: { fontSize: "12pt" }, children: [(0, jsx_runtime_1.jsx)("b", { children: error }), (0, jsx_runtime_1.jsx)("br", {}), "If you are stuck ", (0, jsx_runtime_1.jsx)(contact_1.default, { lower: true }), "."] }), type: "error", showIcon: true })), success && ((0, jsx_runtime_1.jsx)(antd_1.Alert, { style: { marginTop: "20px" }, message: (0, jsx_runtime_1.jsx)("b", { children: "Success" }), description: (0, jsx_runtime_1.jsx)("div", { style: { fontSize: "12pt" }, children: success }), type: "success", showIcon: true }))] }));
    }
    return ((0, jsx_runtime_1.jsxs)("div", { style: { padding: "15px" }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { textAlign: "center", marginBottom: "15px" }, children: [(0, jsx_runtime_1.jsx)(logo_square_1.default, { style: { width: "100px", height: "100px" } }), (0, jsx_runtime_1.jsxs)("h1", { children: [success ? "Successfully " : "", "Verif", success ? "ied" : "y", " Your Email Address"] })] }), (0, jsx_runtime_1.jsx)("div", { style: shared_1.LOGIN_STYLE, children: (0, jsx_runtime_1.jsx)(Body, {}) })] }));
}
exports.default = RedeemVerifyEmail;
//# sourceMappingURL=redeem-verify-email.js.map