import { __awaiter } from "tslib";
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef } from '@angular/core';
import { FirstUppercaseLocalizeSAPipe } from '@anglr/common';
import { RelationsNodeBase, RelationNodeInputSAComponent, RelationNodeOutputSAComponent, RelationsNodeHeaderSAComponent } from '@anglr/dynamic/relations-editor';
import { TitledDialogService } from '@anglr/common/material';
import { HandlebarsLanguageModel, CodeEditorDialogComponent } from '@anglr/dynamic';
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 data template
 */
export class DataTemplateNodeSAComponent extends RelationsNodeBase {
    //######################### constructor #########################
    constructor(changeDetector, element, dialog) {
        super(changeDetector, element);
        this.dialog = dialog;
    }
    //######################### protected methods - template bindings #########################
    /**
     * Shows code editor
     */
    showCodeEditor() {
        var _a, _b, _c, _d;
        return __awaiter(this, void 0, void 0, function* () {
            const result = yield lastValueFrom(this.dialog.open(CodeEditorDialogComponent, {
                title: 'Code editor',
                width: '75vw',
                height: '75vh',
                data: {
                    content: (_c = (_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.relationsOptions) === null || _b === void 0 ? void 0 : _b.template) !== null && _c !== void 0 ? _c : '',
                    languageModel: HandlebarsLanguageModel,
                }
            }).afterClosed());
            if (isPresent(result)) {
                if ((_d = this.metadata) === null || _d === void 0 ? void 0 : _d.relationsOptions) {
                    this.metadata.relationsOptions.template = result.content;
                    this.history.getNewState();
                }
            }
        });
    }
}
DataTemplateNodeSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: DataTemplateNodeSAComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1.TitledDialogService }], target: i0.ɵɵFactoryTarget.Component });
DataTemplateNodeSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: DataTemplateNodeSAComponent, isStandalone: true, selector: "data-template-node", usesInheritance: true, ngImport: i0, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'data template'|firstUppercaseLocalize\"></relations-node-header>\n\n<div class=\"node-content\">\n    <div class=\"inputs-outputs\">\n        <div class=\"inputs\">\n            <div class=\"input\">\n                <relation-node-input [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"template\" [parent]=\"this\"></relation-node-input>\n                <div>{{'template'|firstUppercaseLocalize}}</div>\n            </div>\n            \n            <div class=\"input\">\n                <relation-node-input [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"data\" [parent]=\"this\"></relation-node-input>\n                <div>{{'data'|firstUppercaseLocalize}}</div>\n            </div>\n        </div>\n\n        <div class=\"outputs\">\n            <div class=\"output\">\n                <div>{{'output'|firstUppercaseLocalize}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"output\" [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>{{'template'|firstUppercaseLocalize}}</span>\n    </button>\n</div>\n", dependencies: [{ 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" }, { kind: "pipe", type: FirstUppercaseLocalizeSAPipe, name: "firstUppercaseLocalize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: DataTemplateNodeSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'data-template-node', standalone: true, imports: [
                        RelationsNodeHeaderSAComponent,
                        RelationNodeInputSAComponent,
                        RelationNodeOutputSAComponent,
                        FirstUppercaseLocalizeSAPipe,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'data template'|firstUppercaseLocalize\"></relations-node-header>\n\n<div class=\"node-content\">\n    <div class=\"inputs-outputs\">\n        <div class=\"inputs\">\n            <div class=\"input\">\n                <relation-node-input [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"template\" [parent]=\"this\"></relation-node-input>\n                <div>{{'template'|firstUppercaseLocalize}}</div>\n            </div>\n            \n            <div class=\"input\">\n                <relation-node-input [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"data\" [parent]=\"this\"></relation-node-input>\n                <div>{{'data'|firstUppercaseLocalize}}</div>\n            </div>\n        </div>\n\n        <div class=\"outputs\">\n            <div class=\"output\">\n                <div>{{'output'|firstUppercaseLocalize}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"output\" [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>{{'template'|firstUppercaseLocalize}}</span>\n    </button>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1.TitledDialogService }] });
//# sourceMappingURL=dataTemplateNode.component.js.map