var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { jsx as _jsx } from "react/jsx-runtime";
import {} from 'react';
const PRELOADED_COMPONENTS = {};
function getIdentifier(component) {
    return `${component.py_module}.${component.js_name}`;
}
export function preloadAuthComponent(importers, component) {
    return __awaiter(this, void 0, void 0, function* () {
        const importer = importers[component.py_module];
        if (!importer) {
            throw new Error(`Missing importer for module ${component.py_module}`);
        }
        let moduleContent = null;
        try {
            moduleContent = yield importer();
        }
        catch (err) {
            throw new Error(`Failed to import module ${component.py_module}`, err);
        }
        if (!moduleContent) {
            throw new Error(`Failed to import module ${component.py_module}`);
        }
        const Component = moduleContent[component.js_name];
        if (!Component) {
            throw new Error(`Failed to import component ${component.js_name} from module ${component.py_module}`);
        }
        PRELOADED_COMPONENTS[getIdentifier(component)] = _jsx(Component, {});
    });
}
/**
 * Simplified version of DynamicComponent, just for the auth components.
 * This is because we can't use the component registry for auth components, since the component registry operates
 * in an authenticated context, and we need to be able to render the login page without being authenticated.
 */
function DynamicAuthComponent(props) {
    const identifier = getIdentifier(props.component);
    // should not happen
    if (!(identifier in PRELOADED_COMPONENTS)) {
        throw new Error(`Component ${identifier} not found`);
    }
    return PRELOADED_COMPONENTS[identifier];
}
export default DynamicAuthComponent;
//# sourceMappingURL=dynamic-auth-component.js.map