"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 __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Disclaimer = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var antd_1 = require("antd");
var A_1 = __importDefault(require("components/misc/A"));
var compare_json_1 = __importDefault(require("./compare.json"));
var icon_1 = require("@cocalc/frontend/components/icon");
var contact_1 = __importDefault(require("components/landing/contact"));
function Compare(_a) {
    var e_1, _b;
    var name = _a.name, disclaimer = _a.disclaimer, title = _a.title;
    var v = [];
    try {
        for (var DATA_1 = __values(compare_json_1.default), DATA_1_1 = DATA_1.next(); !DATA_1_1.done; DATA_1_1 = DATA_1.next()) {
            var table = DATA_1_1.value;
            if (name != null && table.name != name)
                continue;
            v.push((0, jsx_runtime_1.jsx)(ComparisonTable, { table: table, disclaimer: disclaimer, title: title }, table.name));
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (DATA_1_1 && !DATA_1_1.done && (_b = DATA_1.return)) _b.call(DATA_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return (0, jsx_runtime_1.jsx)("div", __assign({ style: { background: "white", width: "100%" } }, { children: v }));
}
exports.default = Compare;
function cmp(a, b) {
    a = "".concat(a);
    b = "".concat(b);
    if (a < b)
        return -1;
    if (a > b)
        return 1;
    return 0;
}
function ComparisonTable(_a) {
    var e_2, _b;
    var table = _a.table, disclaimer = _a.disclaimer, title = _a.title;
    var columns = [
        {
            title: "Feature",
            dataIndex: "feature",
            key: "feature",
            width: "25%",
        },
    ];
    var _loop_1 = function (product) {
        columns.push({
            width: "".concat(75 / table.products.length, "%"),
            title: (product.link ? ((0, jsx_runtime_1.jsx)(A_1.default, __assign({ href: product.link, alt: "Link to information about this product" }, { children: product.name }))) : (product.name)),
            key: product.key,
            dataIndex: product.key,
            // @ts-ignore
            render: function (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 });
                }
                var type;
                var note;
                var 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", __assign({ style: { color: "#666", fontSize: "9pt" } }, { children: note }))), link && ((0, jsx_runtime_1.jsx)(A_1.default, __assign({ style: { fontSize: "7pt" }, href: link }, { children: link })))] }));
            },
            sorter: function (a, b) { return cmp(a[product.key], b[product.key]); },
        });
    };
    try {
        for (var _c = __values(table.products), _d = _c.next(); !_d.done; _d = _c.next()) {
            var product = _d.value;
            _loop_1(product);
        }
    }
    catch (e_2_1) { e_2 = { error: e_2_1 }; }
    finally {
        try {
            if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
        }
        finally { if (e_2) throw e_2.error; }
    }
    return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: {
            margin: "auto",
            padding: "30px",
            overflowX: "auto",
        } }, { children: [title ? (title) : ((0, jsx_runtime_1.jsxs)("h1", __assign({ style: { textAlign: "center" } }, { children: [table.title, "\u00A0\u00A0\u00A0\u00A0", (0, jsx_runtime_1.jsx)(A_1.default, __assign({ 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(_a) {
    var type = _a.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", __assign({ 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", __assign({ 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