import { UmbHealthCheckContext } from './health-check.context.js';
import { UmbContextBase } from '../../libs/class-api/index.js';
import { UmbContextToken } from '../../libs/context-api/index.js';
import { loadManifestApi } from '../../libs/extension-api/index.js';
export class UmbHealthCheckDashboardContext extends UmbContextBase {
    #manifests;
    set manifests(value) {
        this.#manifests = value;
        this.#registerApis();
    }
    get manifests() {
        return this.#manifests;
    }
    constructor(host) {
        super(host, UMB_HEALTHCHECK_DASHBOARD_CONTEXT);
        this.#manifests = [];
        this.apis = new Map();
    }
    async checkAll() {
        for (const [label, api] of this.apis.entries()) {
            await api?.checkGroup?.(label);
        }
    }
    #registerApis() {
        this.apis.clear();
        this.#manifests.forEach(async (manifest) => {
            if (!manifest.api)
                return;
            const api = await loadManifestApi(manifest.api);
            if (!api)
                return;
            const apiInstance = new api(this);
            if (api && UmbHealthCheckContext.isInstanceLike(apiInstance))
                this.apis.set(manifest.meta.label, apiInstance);
        });
    }
}
export const UMB_HEALTHCHECK_DASHBOARD_CONTEXT = new UmbContextToken('UmbHealthCheckDashboardContext');
