"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 __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
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 });
var jsx_runtime_1 = require("react/jsx-runtime");
/*
 *  This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var react_1 = require("react");
var antd_1 = require("antd");
var code_1 = __importDefault(require("components/landing/code"));
var lodash_1 = require("lodash");
var executables_1 = __importDefault(require("lib/landing/executables"));
var Text = antd_1.Typography.Text;
var INFO_STYLE = {
    overflow: "auto",
    maxHeight: "10em",
    maxWidth: "40vw",
    backgroundColor: "rgba(150, 150, 150, 0.1)",
    fontSize: "10px",
    border: "none",
    borderRadius: "3px",
};
var PRE_STYLE = {
    padding: "5px",
    margin: 0,
    overflow: "unset", // parent div will show scroll handles
};
var COLUMNS = [
    {
        title: "Name",
        key: "name",
        dataIndex: "name",
        responsive: ["md"],
        render: function (name) { return ((0, jsx_runtime_1.jsx)(Text, __assign({ strong: true, style: { fontSize: "12pt" } }, { children: name }))); },
    },
    {
        title: "Path",
        key: "path",
        dataIndex: "path",
        render: function (path) { return (0, jsx_runtime_1.jsx)(code_1.default, { children: path }); },
    },
    {
        title: "Information",
        key: "output",
        dataIndex: "output",
        width: "40%",
        render: function (output) { return ((0, jsx_runtime_1.jsx)("div", __assign({ style: INFO_STYLE }, { children: (0, jsx_runtime_1.jsx)("pre", __assign({ style: PRE_STYLE }, { children: output })) }))); },
    },
];
function ExecutablesTable(_a) {
    var e_1, _b;
    var executablesSpec = _a.executablesSpec;
    var dataSource = (0, executables_1.default)(executablesSpec);
    var _c = __read((0, react_1.useState)(""), 2), search = _c[0], setSearch = _c[1];
    var onChange = (0, react_1.useMemo)(function () {
        return (0, lodash_1.debounce)(function (e) {
            setSearch(e.target.value);
        }, 300);
    }, []);
    var data;
    if (!search) {
        data = dataSource;
    }
    else {
        var s = search.toLowerCase();
        data = [];
        try {
            for (var dataSource_1 = __values(dataSource), dataSource_1_1 = dataSource_1.next(); !dataSource_1_1.done; dataSource_1_1 = dataSource_1.next()) {
                var x = dataSource_1_1.value;
                if (x.path.includes(s)) {
                    data.push(x);
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (dataSource_1_1 && !dataSource_1_1.done && (_b = dataSource_1.return)) _b.call(dataSource_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
    }
    return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: { clear: "both" } }, { children: [(0, jsx_runtime_1.jsxs)("h2", { children: ["Showing ", data.length, " executables"] }), (0, jsx_runtime_1.jsx)(antd_1.Input.Search, { style: { padding: "0 30px 15px 0", width: "50%", minWidth: "300px" }, placeholder: "Search...", allowClear: true, onChange: onChange, onPressEnter: function (e) { return setSearch(e.target.value); } }), (0, jsx_runtime_1.jsx)("div", __assign({ style: { overflowX: "auto", width: "100%" } }, { children: (0, jsx_runtime_1.jsx)(antd_1.Table, { columns: COLUMNS, bordered: true, pagination: false, rowKey: "path", dataSource: data }) }))] })));
}
exports.default = ExecutablesTable;
//# sourceMappingURL=executables-table.js.map