import { Component, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef } from '@angular/core';
import { FirstUppercaseLocalizeSAPipe } from '@anglr/common';
import { TitledDialogService } from '@anglr/common/material';
import { CodeEditorDialogComponent, getJson, JsonLanguageModel } from '@anglr/dynamic';
import { RelationsNodeBase, RelationNodeOutputSAComponent, RelationsNodeHeaderSAComponent } from '@anglr/dynamic/relations-editor';
import { isPresent } from '@jscrpt/common';
import { lastValueFrom } from '@jscrpt/common/rxjs';
import * as i0 from "@angular/core";
import * as i1 from "@anglr/common/material";
/**
 * Relations node component for value
 */
export class ValueNodeSAComponent extends RelationsNodeBase {
    //######################### constructor #########################
    constructor(changeDetector, element, dialog) {
        super(changeDetector, element);
        this.dialog = dialog;
    }
    //######################### protected methods - template bindings #########################
    /**
     * Shows code editor
     */
    async showCodeEditor() {
        const content = isPresent(this.metadata?.relationsOptions?.value) ? JSON.stringify(this.metadata?.relationsOptions?.value, null, 4) : '';
        const result = await lastValueFrom(this.dialog.open(CodeEditorDialogComponent, {
            title: 'Code editor',
            width: '75vw',
            height: '75vh',
            data: {
                content,
                languageModel: JsonLanguageModel,
            }
        }).afterClosed());
        if (!this.metadata?.relationsOptions) {
            return;
        }
        if (isPresent(result)) {
            this.metadata.relationsOptions.value = getJson(result.content);
            this.history.getNewState();
        }
    }
}
ValueNodeSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ValueNodeSAComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1.TitledDialogService }], target: i0.ɵɵFactoryTarget.Component });
ValueNodeSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: ValueNodeSAComponent, isStandalone: true, selector: "value-node", usesInheritance: true, ngImport: i0, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'value'|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\">\n                <div>{{'value'|firstUppercaseLocalize}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"value\" [parent]=\"this\"></relation-node-output>\n            </div>\n        </div>\n    </div>\n\n    <button type=\"button\" class=\"dynamic-btn dynamic-btn-primary\" (click)=\"showCodeEditor()\">\n        <span>{{'edit'|firstUppercaseLocalize}}</span>\n    </button>\n</div>", dependencies: [{ 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: ValueNodeSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'value-node', standalone: true, imports: [
                        RelationsNodeHeaderSAComponent,
                        RelationNodeOutputSAComponent,
                        FirstUppercaseLocalizeSAPipe,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'value'|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\">\n                <div>{{'value'|firstUppercaseLocalize}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"value\" [parent]=\"this\"></relation-node-output>\n            </div>\n        </div>\n    </div>\n\n    <button type=\"button\" class=\"dynamic-btn dynamic-btn-primary\" (click)=\"showCodeEditor()\">\n        <span>{{'edit'|firstUppercaseLocalize}}</span>\n    </button>\n</div>" }]
        }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1.TitledDialogService }] });
//# sourceMappingURL=valueNode.component.js.map