import { __awaiter } from "tslib";
import { Directive, inject, Input } from '@angular/core';
import { RelationsComponentManager, RelationsProcessor } from '@anglr/dynamic/relations';
import { nameof } from '@jscrpt/common';
import { ListBlockRelations } from '../../../listBlock.relations';
import * as i0 from "@angular/core";
/**
 * Directive that creates list block scoped relations component
 */
export class ListBlockScopeRelationsSADirective {
    constructor() {
        //######################### protected properties #########################
        /**
         * Indication whether is component initialized
         */
        this.initialized = false;
        /**
         * Instance of relations component manager
         */
        this.componentManager = inject(RelationsComponentManager);
        /**
         * Instance of relations processor
         */
        this.relationsProcessor = inject(RelationsProcessor);
        /**
         * Instance of relations component
         */
        this.relations = new ListBlockRelations();
        //######################### public properties - inputs #########################
        /**
         * Instance of datum assigned to this item in list
         */
        this.datum = null;
        /**
         * Index of assigned datum to this item in list
         */
        this.index = 0;
        /**
         * Indication whether is this first item in list
         */
        this.first = false;
        /**
         * Indication whether is this last item in list
         */
        this.last = false;
        /**
         * Id of component that is being created
         */
        this.componentId = '';
    }
    //######################### public methods - implementation of OnChanges #########################
    /**
     * Called when input value changes
     */
    ngOnChanges(changes) {
        return __awaiter(this, void 0, void 0, function* () {
            if (nameof('componentId') in changes && !this.initialized && this.componentId) {
                this.initialized = true;
                this.componentManager.registerComponent(this.componentId, this.relations);
                yield this.relationsProcessor.initialized;
                this.relationsProcessor.updateRelations(this.componentId);
            }
            if (nameof('datum') in changes) {
                this.relations.datum = this.datum;
            }
            if (nameof('index') in changes) {
                this.relations.index = this.index;
            }
            if (nameof('first') in changes) {
                this.relations.first = this.first;
            }
            if (nameof('last') in changes) {
                this.relations.last = this.last;
            }
        });
    }
    //######################### public methods - implementation of OnDestroy #########################
    /**
     * Called when component is destroyed
     */
    ngOnDestroy() {
        this.relationsProcessor.destroyComponent(this.componentId);
        this.componentManager.unregisterComponent(this.componentId);
    }
}
ListBlockScopeRelationsSADirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ListBlockScopeRelationsSADirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
ListBlockScopeRelationsSADirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.0.4", type: ListBlockScopeRelationsSADirective, isStandalone: true, selector: "[listBlockScope]", inputs: { datum: "datum", index: "index", first: "first", last: "last", componentId: "componentId" }, usesOnChanges: true, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ListBlockScopeRelationsSADirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[listBlockScope]',
                    standalone: true,
                }]
        }], propDecorators: { datum: [{
                type: Input
            }], index: [{
                type: Input
            }], first: [{
                type: Input
            }], last: [{
                type: Input
            }], componentId: [{
                type: Input
            }] } });
//# sourceMappingURL=listBlockScopeRelations.directive.js.map