"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 });
var jsx_runtime_1 = require("react/jsx-runtime");
var api_1 = __importDefault(require("lib/hooks/api"));
var loading_1 = __importDefault(require("components/share/loading"));
var license_1 = require("./license");
var antd_1 = require("antd");
var Option = antd_1.Select.Option;
var misc_1 = require("@cocalc/util/misc");
function SelectLicense(_a) {
    var e_1, _b;
    var _c;
    var onSelect = _a.onSelect, license = _a.license, style = _a.style, disabled = _a.disabled;
    var _d = (0, api_1.default)("licenses/get-managed"), result = _d.result, error = _d.error;
    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, { style: { fontSize: "16pt", margin: "auto" } });
    }
    var v = [];
    try {
        for (var result_1 = __values(result), result_1_1 = result_1.next(); !result_1_1.done; result_1_1 = result_1.next()) {
            var x = result_1_1.value;
            v.push((0, jsx_runtime_1.jsxs)(Option, __assign({ value: x.id, search: "".concat(x.id, " ").concat(x.title, " ").concat(x.description, " ").concat(JSON.stringify(x.quota)).toLowerCase() }, { children: [((_c = x.title) === null || _c === void 0 ? void 0 : _c.trim()) ? "".concat(x.title, " - ") : '', (0, jsx_runtime_1.jsx)("span", __assign({ style: { fontFamily: "monospace" } }, { children: x.id })), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)(license_1.Quota, { quota: x.quota })] }), x.id));
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (result_1_1 && !result_1_1.done && (_b = result_1.return)) _b.call(result_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return ((0, jsx_runtime_1.jsx)(antd_1.Select, __assign({ style: style, disabled: disabled, showSearch: true, allowClear: true, placeholder: "Select a license", optionFilterProp: "children", value: license ? license : undefined /* no empty string so placeholder works */, onChange: onSelect, filterOption: function (input, option) {
            var _a;
            if (!input.trim())
                return true;
            return (0, misc_1.search_match)((_a = option === null || option === void 0 ? void 0 : option.search) !== null && _a !== void 0 ? _a : "", (0, misc_1.search_split)(input));
        } }, { children: v })));
}
exports.default = SelectLicense;
//# sourceMappingURL=select-license.js.map