import { adminCrudInputCompilerSpec, createPlatformPluginExport, ModelFieldUtils, } from '@baseplate-dev/project-builder-lib';
import { adminCrudFileInputGenerator } from '#src/generators/react/admin-crud-file-input/index.js';
function buildFileTransformerCompiler() {
    return {
        name: 'file',
        compileInput(definition, { order, definitionContainer, model }) {
            const transformer = model.service.transformers.find((t) => t.id === definition.modelRelationRef && t.type === 'file');
            const relation = model.model.relations?.find((r) => r.id === transformer?.fileRelationRef);
            if (!relation) {
                throw new Error(`Could not find relation ${definition.modelRelationRef} in model ${model.name}`);
            }
            const category = transformer?.category;
            if (!category) {
                throw new Error(`Could not find category for relation ${relation.foreignRelationName}`);
            }
            const isOptional = ModelFieldUtils.isRelationOptional(model, relation);
            const relationName = definitionContainer.nameFromId(definition.modelRelationRef);
            return adminCrudFileInputGenerator({
                order,
                label: definition.label,
                isOptional,
                category: category.name,
                modelRelation: relationName,
            });
        },
    };
}
export default createPlatformPluginExport({
    dependencies: {
        adminCrudInputCompiler: adminCrudInputCompilerSpec,
    },
    exports: {},
    initialize: ({ adminCrudInputCompiler }) => {
        adminCrudInputCompiler.registerCompiler(buildFileTransformerCompiler());
        return {};
    },
});
//# sourceMappingURL=node.js.map