import { adminCrudInputCompilerSpec, createPluginModule, 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}`);
            }
            if (!transformer?.categoryRef) {
                throw new Error(`Could not find category for relation ${relation.foreignRelationName}`);
            }
            const categoryName = definitionContainer.nameFromId(transformer.categoryRef);
            const isOptional = ModelFieldUtils.isRelationOptional(model, relation);
            const relationName = definitionContainer.nameFromId(definition.modelRelationRef);
            return adminCrudFileInputGenerator({
                order,
                label: definition.label,
                isOptional,
                category: categoryName,
                modelRelation: relationName,
            });
        },
    };
}
export default createPluginModule({
    name: 'node',
    dependencies: {
        adminCrudInputCompiler: adminCrudInputCompilerSpec,
    },
    initialize: ({ adminCrudInputCompiler }) => {
        adminCrudInputCompiler.inputs.add(buildFileTransformerCompiler());
    },
});
//# sourceMappingURL=node.js.map