"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Disclaimer = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const antd_1 = require("antd");
const A_1 = __importDefault(require("components/misc/A"));
const compare_json_1 = __importDefault(require("./compare.json"));
const icon_1 = require("@cocalc/frontend/components/icon");
const contact_1 = __importDefault(require("components/landing/contact"));
function Compare({ name, disclaimer, title }) {
    const v = [];
    for (const table of compare_json_1.default) {
        if (name != null && table.name != name)
            continue;
        v.push((0, jsx_runtime_1.jsx)(ComparisonTable, { table: table, disclaimer: disclaimer, title: title }, table.name));
    }
    return (0, jsx_runtime_1.jsx)("div", { style: { background: "white", width: "100%" }, children: v });
}
exports.default = Compare;
function cmp(a, b) {
    a = `${a}`;
    b = `${b}`;
    if (a < b)
        return -1;
    if (a > b)
        return 1;
    return 0;
}
function ComparisonTable({ table, disclaimer, title, }) {
    const columns = [
        {
            title: "Feature",
            dataIndex: "feature",
            key: "feature",
            width: "25%",
        },
    ];
    for (const product of table.products) {
        columns.push({
            width: `${75 / table.products.length}%`,
            title: (product.link ? ((0, jsx_runtime_1.jsx)(A_1.default, { href: product.link, alt: "Link to information about this product", children: product.name })) : (product.name)),
            key: product.key,
            dataIndex: product.key,
            // @ts-ignore
            render: (support) => {
                if (support === undefined) {
                    return ((0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "question-circle", style: { color: "#888", fontSize: "20px" } }));
                }
                if (typeof support == "boolean" || support === null) {
                    return (0, jsx_runtime_1.jsx)(SupportMarker, { type: support });
                }
                let type;
                let note;
                let link = "";
                if (typeof support == "string") {
                    type = true;
                    note = support;
                }
                else {
                    type = support.type;
                    note = support.note;
                    link = support.link;
                }
                return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SupportMarker, { type: type }), " ", type !== undefined && (0, jsx_runtime_1.jsx)("br", {}), note && ((0, jsx_runtime_1.jsx)("div", { style: { color: "#666", fontSize: "9pt" }, children: note })), link && ((0, jsx_runtime_1.jsx)(A_1.default, { style: { fontSize: "7pt" }, href: link, children: link }))] }));
            },
            sorter: (a, b) => cmp(a[product.key], b[product.key]),
        });
    }
    return ((0, jsx_runtime_1.jsxs)("div", { style: {
            margin: "auto",
            padding: "30px",
            overflowX: "auto",
        }, children: [title ? (title) : ((0, jsx_runtime_1.jsxs)("h1", { style: { textAlign: "center" }, children: [table.title, "\u00A0\u00A0\u00A0\u00A0", (0, jsx_runtime_1.jsx)(A_1.default, { href: table.link, style: { fontSize: "11pt" }, alt: "Link to learn more about this", children: "learn more" })] })), (0, jsx_runtime_1.jsx)(antd_1.Table, { dataSource: table.rows, columns: columns, bordered: true, pagination: false, rowKey: "feature" }), disclaimer && (0, jsx_runtime_1.jsx)(Disclaimer, {})] }));
}
function SupportMarker({ type }) {
    if (type === true) {
        return (0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "check", style: { color: "green", fontSize: "20px" } });
    }
    else if (type === false) {
        return (0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "times", style: { color: "red", fontSize: "20px" } });
    }
    else if (type === null) {
        return (0, jsx_runtime_1.jsx)("span", { style: { color: "#888" }, children: "N/A" });
    }
    else {
        return null;
    }
}
function Disclaimer() {
    return ((0, jsx_runtime_1.jsx)(antd_1.Alert, { style: { margin: "30px auto", maxWidth: "900px" }, message: "", description: (0, jsx_runtime_1.jsxs)("span", { style: { fontSize: "10pt" }, children: ["These comparisons were made in good faith; however, they may contain errors, since we know CoCalc better and the products are constantly improving. ", (0, jsx_runtime_1.jsx)(contact_1.default, {}), " if anything looks wrong or incomplete!"] }), type: "warning", showIcon: true }));
}
exports.Disclaimer = Disclaimer;
//# sourceMappingURL=compare.js.map