"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");
/*
Select a site license, either by pasting one in, or
from a list of all of the licenses the signed in user
is a manager of.
*/
const react_1 = require("react");
const antd_1 = require("antd");
const select_license_1 = __importDefault(require("@cocalc/frontend/site-licenses/select-license"));
const database_1 = __importDefault(require("lib/hooks/database"));
const loading_1 = __importDefault(require("components/share/loading"));
function SelectSiteLicense({ onChange, defaultLicenseId, }) {
    const { error, value, loading } = (0, database_1.default)({
        manager_site_licenses: [
            { id: null, expires: null, title: null, quota: null },
        ],
    });
    const managedLicenses = (0, react_1.useMemo)(() => {
        const x = {};
        if (!value)
            return x;
        const { manager_site_licenses } = value;
        for (const license of manager_site_licenses) {
            if (license.expires) {
                // comes back from database as ISO string.
                license.expires = new Date(license.expires);
            }
            x[license.id] = license;
        }
        return x;
    }, [value]);
    if (loading || value == null) {
        return (0, jsx_runtime_1.jsx)(loading_1.default, {});
    }
    if (error) {
        return (0, jsx_runtime_1.jsx)(antd_1.Alert, { type: "error", message: error });
    }
    return ((0, jsx_runtime_1.jsx)(select_license_1.default, { onChange: onChange, defaultLicenseId: defaultLicenseId, managedLicenses: managedLicenses }));
}
exports.default = SelectSiteLicense;
//# sourceMappingURL=select-site-license.js.map