"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");
/*
Page that you show user after they successfully complete a purchase.

It queries the backend for "the most recent stuff you bought", thanks
you for your purchase, has useful links, etc.

NOTE: the current implementation is just a really simple one that assumes
you are purchasing a license for projects, since that's all we sell
right now.  This will have to be a bit more sophisticated when there's
more products.
*/
const icon_1 = require("@cocalc/frontend/components/icon");
const r_join_1 = require("@cocalc/frontend/components/r_join");
const misc_1 = require("@cocalc/util/misc");
const antd_1 = require("antd");
const image_1 = __importDefault(require("components/landing/image"));
const license_1 = __importDefault(require("components/licenses/license"));
const A_1 = __importDefault(require("components/misc/A"));
const loading_1 = __importDefault(require("components/share/loading"));
const site_name_1 = __importDefault(require("components/share/site-name"));
const api_1 = __importDefault(require("lib/hooks/api"));
const bella_png_1 = __importDefault(require("public/shopping/bella.png"));
function Congrats() {
    const { result, error } = (0, api_1.default)("/shopping/cart/recent-purchases", {
        recent: "1 day",
    });
    if (error) {
        return (0, jsx_runtime_1.jsx)(antd_1.Alert, { type: "error", message: error });
    }
    if (!result) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, { large: true, center: true });
    }
    if (result.length == 0) {
        return (0, jsx_runtime_1.jsx)("div", { children: "You have no recent purchases." });
    }
    function renderNextSteps() {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h2", { children: "Here are your next steps" }), (0, jsx_runtime_1.jsxs)("ul", { children: [(0, jsx_runtime_1.jsxs)("li", { children: ["You are a manager for each of the licenses you purchased.", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/licenses/managed", children: "You can see your managed licenses" }), ", add other people as managers, edit the title and description of each license, and see how a license is being used."] }), (0, jsx_runtime_1.jsxs)("li", { children: ["You can", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "https://doc.cocalc.com/project-settings.html#project-add-license", children: "apply a license to projects" }), ",", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "https://doc.cocalc.com/teaching-upgrade-course.html#install-course-license", children: "courses" }), ", or directly share the license code, as", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "https://doc.cocalc.com/licenses.html", children: "explained here" }), ". It's time to make your ", (0, jsx_runtime_1.jsx)(site_name_1.default, {}), " projects much, much better."] }), (0, jsx_runtime_1.jsxs)("li", { children: ["You can ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/billing/receipts", children: "download your receipt" }), " and", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/billing/subscriptions", children: "check on the status of subscriptions." })] }), (0, jsx_runtime_1.jsxs)("li", { children: ["If you have questions,", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: "/support/new", children: "create a support ticket" }), ". Now that you're supporting ", (0, jsx_runtime_1.jsx)(site_name_1.default, {}), " we can prioritize your request."] })] })] }));
    }
    function renderAutomaticallyApplied() {
        const appliedProjects = result.filter((x) => x.project_id != null);
        const numApplied = appliedProjects.length;
        if (numApplied == 0)
            return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)(antd_1.Alert, { type: "info", message: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("p", { children: ["The following ", (0, misc_1.plural)(numApplied, "project"), " automatically got a license applied:"] }), (0, jsx_runtime_1.jsx)("ul", { children: appliedProjects.map((x) => ((0, jsx_runtime_1.jsxs)("li", { children: ["Project", " ", (0, jsx_runtime_1.jsx)(A_1.default, { href: `/projects/${x.project_id}`, external: true, children: x.project_id }), " ", "got license ", (0, jsx_runtime_1.jsx)(license_1.default, { license_id: x.purchased?.license_id }), "."] }, x.project_id))) })] }) })] }));
    }
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { style: { float: "right" }, children: (0, jsx_runtime_1.jsx)(image_1.default, { src: bella_png_1.default, width: 100, height: 141, alt: "Picture of a doggie." }) }), (0, jsx_runtime_1.jsxs)("div", { style: { fontSize: "12pt" }, children: [(0, jsx_runtime_1.jsxs)("h1", { style: { fontSize: "24pt" }, children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "check-circle", style: { color: "darkgreen", marginRight: "10px" } }), " ", "Order Complete!"] }), "Congrats! You recently ordered ", result.length >= 2 ? "these" : "this", " ", result.length, " ", (0, jsx_runtime_1.jsx)(site_name_1.default, {}), " ", (0, misc_1.plural)(result.length, "license"), ":", (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("div", { style: { margin: "15px auto", maxWidth: "700px" }, children: (0, r_join_1.r_join)(result.map((item) => ((0, jsx_runtime_1.jsx)(license_1.default, { license_id: item.purchased.license_id }, item.purchased.license_id)))) }), renderAutomaticallyApplied(), (0, jsx_runtime_1.jsx)("br", {}), renderNextSteps()] })] }));
}
exports.default = Congrats;
//# sourceMappingURL=congrats.js.map