import { DynamicItemExtensionBase } from '@anglr/dynamic';
import { RelationsComponentManager, RelationsProcessor } from '../../services';
/**
 * Extension that allows registration of component for relations
 */
export class RelationsRegistrationExtension extends DynamicItemExtensionBase {
    constructor() {
        //######################### protected properties #########################
        super(...arguments);
        /**
         * Instance of relations processor
         */
        this.relationsProcessor = null;
        /**
         * Instance of component manager
         */
        this.componentManager = null;
    }
    //######################### public methods - overrides #########################
    /**
     * @inheritdoc
     */
    async onInit() {
        if (!this.injector || !this.metadata || !this.instance) {
            return;
        }
        this.relationsProcessor ?? (this.relationsProcessor = this.injector.get(RelationsProcessor, null));
        this.componentManager ?? (this.componentManager = this.injector.get(RelationsComponentManager, null));
        if (!this.relationsProcessor || !this.componentManager) {
            return;
        }
        this.componentManager.registerComponent(this.metadata.id, this.instance);
        await this.relationsProcessor.initialized;
        this.relationsProcessor.updateRelations(this.metadata.id);
    }
    /**
     * @inheritdoc
     */
    onDestroy() {
        if (!this.relationsProcessor || !this.componentManager || !this.metadata) {
            return;
        }
        this.relationsProcessor.destroyComponent(this.metadata.id);
        this.componentManager.unregisterComponent(this.metadata.id);
    }
}
//# sourceMappingURL=relationsRegistration.extension.js.map