import { Component, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FirstUppercaseLocalizeSAPipe } from '@anglr/common';
import { RelationsNodeBase, RelationNodeOutputSAComponent, RelationsNodeHeaderSAComponent } from '@anglr/dynamic/relations-editor';
import { TitledDialogService } from '@anglr/common/material';
import { extend } from '@jscrpt/common';
import { lastValueFrom } from '@jscrpt/common/rxjs';
import { ConfigureNodeEndpointSAComponent } from '../../../components';
import * as i0 from "@angular/core";
import * as i1 from "@anglr/common/material";
import * as i2 from "@angular/common";
/**
 * Relations node component for component inputs
 */
export class ComponentInputsNodeSAComponent extends RelationsNodeBase {
    //######################### protected properties - template bindings #########################
    /**
     * Gets component inputs
     */
    get endpoints() {
        var _a, _b;
        if (!this.metadata) {
            return [];
        }
        (_a = this.metadata).relationsOptions ?? (_a.relationsOptions = {
            inputs: []
        });
        return ((_b = this.metadata.relationsOptions).inputs ?? (_b.inputs = []));
    }
    //######################### constructor #########################
    constructor(changeDetector, element, dialog) {
        super(changeDetector, element);
        this.dialog = dialog;
    }
    //######################### protected methods - template bindings #########################
    /**
     * Adds new input endpoint
     */
    async addEndpoint() {
        const param = {
            name: '',
            defaultValue: null,
            skipInit: false,
            allowSkipInit: true,
        };
        if (await this.configureEndpoint(param)) {
            this.endpoints.push(param);
            this.history.getNewState();
        }
    }
    /**
     * Removes endpoint
     * @param endpoint - Endpoint to be removed
     */
    removeEndpoint(endpoint) {
        const index = this.endpoints.indexOf(endpoint);
        if (index >= 0) {
            this.endpoints.splice(index, 1);
            this.history.getNewState();
        }
    }
    /**
     * Configures endpoint
     * @param endpoint - Endpoint to be configured
     */
    async configureEndpoint(endpoint) {
        const original = JSON.parse(JSON.stringify(endpoint));
        const result = await lastValueFrom(this.dialog.open(ConfigureNodeEndpointSAComponent, {
            title: 'configure component input',
            width: '60vw',
            data: endpoint
        }).afterClosed());
        if (!result) {
            extend(endpoint, original);
        }
        else {
            this.history.getNewState();
        }
        return result ?? false;
    }
}
ComponentInputsNodeSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ComponentInputsNodeSAComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1.TitledDialogService }], target: i0.ɵɵFactoryTarget.Component });
ComponentInputsNodeSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: ComponentInputsNodeSAComponent, isStandalone: true, selector: "component-inputs-node", usesInheritance: true, ngImport: i0, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'component inputs'|firstUppercaseLocalize\"></relations-node-header>\n\n<div class=\"node-content\">\n    <div class=\"inputs-outputs\">\n        <div class=\"inputs\">\n        </div>\n\n        <div class=\"outputs\">\n            <div class=\"output\" *ngFor=\"let endpoint of endpoints\">\n                <div class=\"dynamic-flex-row\">\n                    <div>{{endpoint.name}}</div>\n\n                    <button type=\"button\" class=\"dynamic-btn-icon dynamic-margin-horizontal-extra-small\" (click)=\"$event.preventDefault(); $event.stopPropagation(); configureEndpoint(endpoint)\">\n                        <span class=\"fas fa-cog\"></span>\n                    </button>\n\n                    <button type=\"button\" class=\"dynamic-btn-icon\" (click)=\"$event.preventDefault(); $event.stopPropagation(); removeEndpoint(endpoint)\">\n                        <span class=\"fas fa-times\"></span>\n                    </button>\n                </div>\n\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" [name]=\"endpoint.name\" [parent]=\"this\"></relation-node-output>\n            </div>\n\n            <div class=\"dynamic-flex-row dynamic-flex-end\">\n                <button type=\"button\" class=\"dynamic-btn-icon dynamic-margin-right-extra-small\" (click)=\"$event.preventDefault(); $event.stopPropagation(); addEndpoint()\">\n                    <span class=\"fas fa-plus\"></span>\n                </button>\n            </div>\n        </div>\n    </div>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: RelationsNodeHeaderSAComponent, selector: "relations-node-header", inputs: ["parent", "destroySubject", "name"] }, { kind: "component", type: RelationNodeOutputSAComponent, selector: "relation-node-output" }, { kind: "pipe", type: FirstUppercaseLocalizeSAPipe, name: "firstUppercaseLocalize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ComponentInputsNodeSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'component-inputs-node', standalone: true, imports: [
                        CommonModule,
                        RelationsNodeHeaderSAComponent,
                        RelationNodeOutputSAComponent,
                        FirstUppercaseLocalizeSAPipe,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'component inputs'|firstUppercaseLocalize\"></relations-node-header>\n\n<div class=\"node-content\">\n    <div class=\"inputs-outputs\">\n        <div class=\"inputs\">\n        </div>\n\n        <div class=\"outputs\">\n            <div class=\"output\" *ngFor=\"let endpoint of endpoints\">\n                <div class=\"dynamic-flex-row\">\n                    <div>{{endpoint.name}}</div>\n\n                    <button type=\"button\" class=\"dynamic-btn-icon dynamic-margin-horizontal-extra-small\" (click)=\"$event.preventDefault(); $event.stopPropagation(); configureEndpoint(endpoint)\">\n                        <span class=\"fas fa-cog\"></span>\n                    </button>\n\n                    <button type=\"button\" class=\"dynamic-btn-icon\" (click)=\"$event.preventDefault(); $event.stopPropagation(); removeEndpoint(endpoint)\">\n                        <span class=\"fas fa-times\"></span>\n                    </button>\n                </div>\n\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" [name]=\"endpoint.name\" [parent]=\"this\"></relation-node-output>\n            </div>\n\n            <div class=\"dynamic-flex-row dynamic-flex-end\">\n                <button type=\"button\" class=\"dynamic-btn-icon dynamic-margin-right-extra-small\" (click)=\"$event.preventDefault(); $event.stopPropagation(); addEndpoint()\">\n                    <span class=\"fas fa-plus\"></span>\n                </button>\n            </div>\n        </div>\n    </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1.TitledDialogService }] });
//# sourceMappingURL=componentInputsNode.component.js.map