import {ExportImportTarget} from "./Exporters";
import {Testables} from "../testables";
import {ComponentExporterImporter} from "./ComponentExporterImporter";

// @ts-ignore
const modules = import.meta.glob(['./custom/*ExporterImporter.ts'], {eager: true});
/*********************************************************************************************************
 *********************************************************************************************************
 * NOTE: WE CANNOT IMPORT ANY RUNTIME SYMBOLS FROM ANY COMPONENTS HERE BECAUSE OF GODDAMN CIRCULAR REFERENCES.
 * *********************************************************************************************************
 * *********************************************************************************************************/
export type exportData = (data: any, target: ExportImportTarget) => any
export type importData = (data: any, models: { testables: Testables }) => any
export const exporterImporters: Record<string, ComponentExporterImporter<any, any>> = {}

Object.values(modules).forEach((module: any) => {
    // Find meta objects in the module (assuming they end with "Meta")
    Object.entries(module).forEach(([key, value]) => {
        if (key.endsWith('ExporterImporter')) {
            const exporter = new (value as () => void) as ComponentExporterImporter<any, any>

            exporterImporters[exporter.type] = exporter
        }
    });
})