import { __awaiter } from "tslib";
import { Component, ChangeDetectionStrategy, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RELATIONS_METADATA_STORAGE } from '@anglr/dynamic/relations';
import { RelationsNodeBase, RelationNodeInputSAComponent, RelationsNodeHeaderSAComponent, RelationNodeOutputSAComponent } from '@anglr/dynamic/relations-editor';
import { LayoutComponentsRegister } from '../../../services';
import { getInputs, getOutputs } from '../customComponent.utils';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
/**
 * Relations node component for custom component
 */
export class CustomComponentNodeSAComponent extends RelationsNodeBase {
    constructor() {
        super(...arguments);
        //######################### protected properties #########################
        /**
         * Storage for relations metadata
         */
        this.relationsMetadataStorage = inject(RELATIONS_METADATA_STORAGE);
        /**
         * Layout components register instance
         */
        this.layoutComponentsRegister = inject(LayoutComponentsRegister);
    }
    //######################### public methods - overrides #########################
    /**
     * @inheritdoc
     */
    initialize() {
        var _a, _b, _c;
        var _d;
        return __awaiter(this, void 0, void 0, function* () {
            if (!this.metadata) {
                return;
            }
            (_a = (_d = this.metadata).relationsOptions) !== null && _a !== void 0 ? _a : (_d.relationsOptions = {
                name: ''
            });
            const componentName = yield this.layoutComponentsRegister.getComponentName(this.metadata.name);
            if (!componentName) {
                return;
            }
            this.metadata.relationsOptions.name = this.metadata.name;
            const relations = (_c = yield ((_b = this.relationsMetadataStorage) === null || _b === void 0 ? void 0 : _b.getMetadata(componentName))) !== null && _c !== void 0 ? _c : [];
            this.inputsMeta = getInputs(relations);
            this.outputsMeta = getOutputs(relations);
        });
    }
}
CustomComponentNodeSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: CustomComponentNodeSAComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
CustomComponentNodeSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: CustomComponentNodeSAComponent, isStandalone: true, selector: "custom-component-node", usesInheritance: true, ngImport: i0, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" name=\"custom\"></relations-node-header>\n\n<div class=\"node-content\">\n    <div class=\"inputs-outputs\">\n        <div class=\"inputs\">\n            <div class=\"input\" *ngFor=\"let inputMeta of inputsMeta?.relationsOptions?.inputs\">\n                <relation-node-input [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" [name]=\"inputMeta.name\" [parent]=\"this\"></relation-node-input>\n                <div>{{inputMeta.name}}</div>\n            </div>\n        </div>\n\n        <div class=\"outputs\">\n            <div class=\"output\" *ngFor=\"let outputMeta of outputsMeta?.relationsOptions?.outputs\">\n                <div>{{outputMeta.name}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" [name]=\"outputMeta.name\" [parent]=\"this\"></relation-node-output>\n            </div>\n        </div>\n    </div>\n</div>", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: RelationsNodeHeaderSAComponent, selector: "relations-node-header", inputs: ["parent", "destroySubject", "name"] }, { kind: "component", type: RelationNodeInputSAComponent, selector: "relation-node-input" }, { kind: "component", type: RelationNodeOutputSAComponent, selector: "relation-node-output" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: CustomComponentNodeSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'custom-component-node', standalone: true, imports: [
                        CommonModule,
                        RelationsNodeHeaderSAComponent,
                        RelationNodeInputSAComponent,
                        RelationNodeOutputSAComponent,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" name=\"custom\"></relations-node-header>\n\n<div class=\"node-content\">\n    <div class=\"inputs-outputs\">\n        <div class=\"inputs\">\n            <div class=\"input\" *ngFor=\"let inputMeta of inputsMeta?.relationsOptions?.inputs\">\n                <relation-node-input [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" [name]=\"inputMeta.name\" [parent]=\"this\"></relation-node-input>\n                <div>{{inputMeta.name}}</div>\n            </div>\n        </div>\n\n        <div class=\"outputs\">\n            <div class=\"output\" *ngFor=\"let outputMeta of outputsMeta?.relationsOptions?.outputs\">\n                <div>{{outputMeta.name}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" [name]=\"outputMeta.name\" [parent]=\"this\"></relation-node-output>\n            </div>\n        </div>\n    </div>\n</div>" }]
        }] });
//# sourceMappingURL=customComponentNode.component.js.map