"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");
const api_1 = __importDefault(require("lib/hooks/api"));
const loading_1 = __importDefault(require("components/share/loading"));
const license_1 = require("./license");
const antd_1 = require("antd");
const { Option } = antd_1.Select;
const misc_1 = require("@cocalc/util/misc");
function SelectLicense({ onSelect, license, style, disabled, }) {
    let { result, error } = (0, api_1.default)("licenses/get-managed");
    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" } });
    }
    const v = [];
    for (const x of result) {
        v.push((0, jsx_runtime_1.jsxs)(Option, { value: x.id, search: `${x.id} ${x.title} ${x.description} ${JSON.stringify(x.quota)}`.toLowerCase(), children: [x.title?.trim() ? `${x.title} - ` : '', (0, jsx_runtime_1.jsx)("span", { 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));
    }
    return ((0, jsx_runtime_1.jsx)(antd_1.Select, { 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: (input, option) => {
            if (!input.trim())
                return true;
            return (0, misc_1.search_match)(option?.search ?? "", (0, misc_1.search_split)(input));
        }, children: v }));
}
exports.default = SelectLicense;
//# sourceMappingURL=select-license.js.map