export class LibraryRegistry {
    static { this.libraries = new Map(); }
    static { this._configured = false; }
    static async Config(forceRefresh = false, componentLibraries) {
        if (!this._configured || forceRefresh) {
            const libraryGroups = new Map();
            for (const lib of componentLibraries) {
                if (!libraryGroups.has(lib.Name.toLowerCase())) {
                    libraryGroups.set(lib.Name.toLowerCase(), []);
                }
                libraryGroups.get(lib.Name.toLowerCase()).push(lib);
            }
            for (const [name, versions] of libraryGroups) {
                const libDef = {
                    name,
                    globalVariable: versions[0].GlobalVariable || "",
                    category: versions[0].Category || "",
                    versions: {},
                    defaultVersion: versions[0].Version || ""
                };
                for (const version of versions) {
                    libDef.versions[version.Version] = {
                        cdnUrl: version.CDNUrl || "",
                        cssUrls: version.CDNCssUrl?.split(",") || []
                    };
                }
                this.libraries.set(name, libDef);
            }
            this._configured = true;
        }
    }
    static getLibrary(name) {
        if (!this._configured)
            throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!");
        return this.libraries.get(name?.trim().toLowerCase());
    }
    static getCdnUrl(name, version) {
        if (!this._configured)
            throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!");
        const library = this.libraries.get(name?.trim().toLowerCase());
        if (!library)
            return undefined;
        const targetVersion = version || library.defaultVersion;
        return library.versions[targetVersion]?.cdnUrl;
    }
    static isApproved(name) {
        if (!this._configured)
            throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!");
        return this.libraries.has(name?.trim().toLowerCase());
    }
    static resolveVersion(name, versionPattern) {
        if (!this._configured)
            throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!");
        const library = this.libraries.get(name?.trim().toLowerCase());
        if (!library)
            return undefined;
        if (!versionPattern)
            return library.defaultVersion;
        if (library.versions[versionPattern]) {
            return versionPattern;
        }
        return library.defaultVersion;
    }
    static registerLibrary(definition) {
        if (!this._configured)
            throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!");
        this.libraries.set(definition.name?.trim().toLowerCase(), definition);
    }
}
//# sourceMappingURL=library-registry.js.map