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
     */
    async editProperties() {
        const result = await lastValueFrom(this.dialog.open(RelationsNodePropertiesEditorSAComponent, {
            title: 'edit properties',
            width: '30vw',
            data: {
                properties: {
                    displayName: this.parent?.metadata?.displayName || this.name || this.parent?.metadata?.id || '',
                    scope: this.parent?.metadata?.scope ?? '',
                },
                scopeConfigurable: this.parent?.metadata?.nodeMetadata?.scopeConfigurable ?? false,
                scopeRegister: this.scopeRegister,
            }
        }).afterClosed());
        if (result && this.parent?.metadata) {
            this.parent.metadata.displayName = result.displayName ?? undefined;
            this.parent.metadata.scope = result.scope ?? 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