import { connectConfig } from "@powerhousedao/connect/config";
import { convertLegacyLibToVetraPackage, } from "@powerhousedao/reactor-browser";
const { externalPackagesEnabled } = connectConfig;
const callbacks = [];
if (import.meta.hot) {
    import.meta.hot.accept("virtual:ph:external-packages", (data) => {
        convertExternalPackages(data)
            .then((packages) => {
            callbacks.forEach((callback) => {
                callback(packages);
            });
        })
            .catch(console.error);
    });
}
function convertExternalPackages(module) {
    return module.loadExternalPackages().then((packages) => {
        return packages.map(convertLegacyLibToVetraPackage);
    });
}
export function subscribeExternalPackages(callback) {
    callbacks.push(callback);
}
export async function loadExternalPackages() {
    try {
        if (!externalPackagesEnabled)
            return [];
        const module = await import("virtual:ph:external-packages");
        return convertExternalPackages(module);
    }
    catch (error) {
        console.error(error);
        return [];
    }
}
//# sourceMappingURL=external-packages.js.map