import { __awaiter } from "tslib";
import { Component, ChangeDetectionStrategy, Input, ChangeDetectorRef, Inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TitledDialogService } from '@anglr/common/material';
import { MetadataHistoryManager } from '@anglr/dynamic';
import { TooltipModule } from '@anglr/common';
import { lastValueFrom } from 'rxjs';
import { RelationsNodePropertiesEditorSAComponent } from '../relationsNodePropertiesEditor/relationsNodePropertiesEditor.component';
import { ToColorSAPipe } from '../../pipes/toColor/toColor.pipe';
import { RELATIONS_HISTORY_MANAGER } from '../../misc/tokens';
import { ScopeRegister } from '../../services';
import * as i0 from "@angular/core";
import * as i1 from "@anglr/common/material";
import * as i2 from "../../services";
import * as i3 from "@angular/common";
import * as i4 from "@anglr/common";
import * as i5 from "@anglr/dynamic";
/**
 * Component used for displaying relations node header
 */
export class RelationsNodeHeaderSAComponent {
    //######################### constructor #########################
    constructor(dialog, changeDetector, scopeRegister, history) {
        this.dialog = dialog;
        this.changeDetector = changeDetector;
        this.scopeRegister = scopeRegister;
        this.history = history;
    }
    //######################### protected methods - template bindings #########################
    /**
     * Opens editation of properties
     */
    editProperties() {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
        return __awaiter(this, void 0, void 0, function* () {
            const result = yield lastValueFrom(this.dialog.open(RelationsNodePropertiesEditorSAComponent, {
                title: 'edit properties',
                width: '30vw',
                data: {
                    properties: {
                        displayName: ((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.displayName) || this.name || ((_d = (_c = this.parent) === null || _c === void 0 ? void 0 : _c.metadata) === null || _d === void 0 ? void 0 : _d.id) || '',
                        scope: (_g = (_f = (_e = this.parent) === null || _e === void 0 ? void 0 : _e.metadata) === null || _f === void 0 ? void 0 : _f.scope) !== null && _g !== void 0 ? _g : '',
                    },
                    scopeConfigurable: (_l = (_k = (_j = (_h = this.parent) === null || _h === void 0 ? void 0 : _h.metadata) === null || _j === void 0 ? void 0 : _j.nodeMetadata) === null || _k === void 0 ? void 0 : _k.scopeConfigurable) !== null && _l !== void 0 ? _l : false,
                    scopeRegister: this.scopeRegister,
                }
            }).afterClosed());
            if (result && ((_m = this.parent) === null || _m === void 0 ? void 0 : _m.metadata)) {
                this.parent.metadata.displayName = (_o = result.displayName) !== null && _o !== void 0 ? _o : undefined;
                this.parent.metadata.scope = (_p = result.scope) !== null && _p !== void 0 ? _p : undefined;
                this.history.getNewState();
                this.changeDetector.detectChanges();
            }
        });
    }
}
RelationsNodeHeaderSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: RelationsNodeHeaderSAComponent, deps: [{ token: i1.TitledDialogService }, { token: i0.ChangeDetectorRef }, { token: i2.ScopeRegister }, { token: RELATIONS_HISTORY_MANAGER }], target: i0.ɵɵFactoryTarget.Component });
RelationsNodeHeaderSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: RelationsNodeHeaderSAComponent, isStandalone: true, selector: "relations-node-header", inputs: { parent: "parent", destroySubject: "destroySubject", name: "name" }, ngImport: i0, template: "<div class=\"header-content\">{{parent?.metadata?.displayName || name || parent?.metadata?.id}}</div>\n\n<span *ngIf=\"parent?.metadata?.scope\" [tooltip]=\"parent?.metadata?.scope\" [style.color]=\"parent?.metadata?.scope | toColor\" class=\"dynamic-margin-horizontal-extra-small dynamic-bold\">&#123;&#125;</span>\n\n<button type=\"button\" class=\"dynamic-btn-icon edit-icon\" (click)=\"editProperties()\">\n    <span class=\"fas fa-pen\"></span>\n</button>\n\n<button type=\"button\" *ngIf=\"destroySubject\" class=\"dynamic-btn-icon destroy-icon\" (click)=\"destroySubject.next()\">\n    <span class=\"fas fa-times\"></span>\n</button>", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: TooltipModule }, { kind: "directive", type: i4.TooltipDirective, selector: "[tooltip]", inputs: ["tooltip", "allowHtml", "template", "tooltipOptions", "tooltipVisible", "containerElement"] }, { kind: "pipe", type: ToColorSAPipe, name: "toColor" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: RelationsNodeHeaderSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'relations-node-header', standalone: true, imports: [
                        CommonModule,
                        TooltipModule,
                        ToColorSAPipe,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"header-content\">{{parent?.metadata?.displayName || name || parent?.metadata?.id}}</div>\n\n<span *ngIf=\"parent?.metadata?.scope\" [tooltip]=\"parent?.metadata?.scope\" [style.color]=\"parent?.metadata?.scope | toColor\" class=\"dynamic-margin-horizontal-extra-small dynamic-bold\">&#123;&#125;</span>\n\n<button type=\"button\" class=\"dynamic-btn-icon edit-icon\" (click)=\"editProperties()\">\n    <span class=\"fas fa-pen\"></span>\n</button>\n\n<button type=\"button\" *ngIf=\"destroySubject\" class=\"dynamic-btn-icon destroy-icon\" (click)=\"destroySubject.next()\">\n    <span class=\"fas fa-times\"></span>\n</button>" }]
        }], ctorParameters: () => [{ type: i1.TitledDialogService }, { type: i0.ChangeDetectorRef }, { type: i2.ScopeRegister }, { type: i5.MetadataHistoryManager, decorators: [{
                    type: Inject,
                    args: [RELATIONS_HISTORY_MANAGER]
                }] }], propDecorators: { parent: [{
                type: Input
            }], destroySubject: [{
                type: Input
            }], name: [{
                type: Input
            }] } });
//# sourceMappingURL=relationsNodeHeader.component.js.map