import { __awaiter } from "tslib";
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef } from '@angular/core';
import { CodeEditorDialogComponent, TypescriptLanguageModel } from '@anglr/dynamic';
import { RelationsNodeBase, RelationNodeOutputSAComponent, RelationsNodeHeaderSAComponent, RelationNodeInputSAComponent } from '@anglr/dynamic/relations-editor';
import { TitledDialogService } from '@anglr/common/material';
import { FirstUppercaseLocalizeSAPipe } from '@anglr/common';
import { generateId } from '@jscrpt/common';
import { lastValueFrom } from '@jscrpt/common/rxjs';
import { languages } from 'monaco-editor';
import typings from '!!raw-loader?esModule!@anglr/dynamic/typings/transformData';
import * as i0 from "@angular/core";
import * as i1 from "@anglr/common/material";
languages.typescript.typescriptDefaults.addExtraLib(typings, 'file:///node_modules/@types/transformData/index.d.ts');
/**
 * Relations node component for transform data
 */
export class TransformDataNodeSAComponent 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, _e, _f;
        var _g;
        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: (_d = (_c = (_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.nodeMetadata) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.content) !== null && _d !== void 0 ? _d : '',
                    languageModel: TypescriptLanguageModel(`import {TransformData} from 'transformData';

/**
 * Transformer function that performs transformation
 */
const transformer: TransformData<any, any> = data =>
{
    return data;
};
 
export default transformer;
`),
                }
            }).afterClosed());
            if (!((_e = this.metadata) === null || _e === void 0 ? void 0 : _e.relationsOptions) || !result || !this.metadata.nodeMetadata) {
                return;
            }
            this.metadata.relationsOptions.code = result.code;
            (_f = (_g = this.metadata.nodeMetadata).options) !== null && _f !== void 0 ? _f : (_g.options = { content: '' });
            this.metadata.nodeMetadata.options.content = result.content;
            this.history.getNewState();
        });
    }
    //######################### protected methods - overrides #########################
    /**
     * @inheritdoc
     */
    metadataSet() {
        var _a, _b;
        var _c;
        if ((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.relationsOptions) {
            (_b = (_c = this.metadata.relationsOptions).id) !== null && _b !== void 0 ? _b : (_c.id = generateId(12));
        }
    }
}
TransformDataNodeSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: TransformDataNodeSAComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1.TitledDialogService }], target: i0.ɵɵFactoryTarget.Component });
TransformDataNodeSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: TransformDataNodeSAComponent, isStandalone: true, selector: "transform-data-node", usesInheritance: true, ngImport: i0, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'transform data'|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=\"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>{{'transformed data'|firstUppercaseLocalize}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"transformedData\" [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>{{'code'|firstUppercaseLocalize}}</span>\n    </button>\n</div>", 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: TransformDataNodeSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'transform-data-node', standalone: true, imports: [
                        RelationsNodeHeaderSAComponent,
                        RelationNodeInputSAComponent,
                        RelationNodeOutputSAComponent,
                        FirstUppercaseLocalizeSAPipe
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<relations-node-header [parent]=\"this\" [destroySubject]=\"destroySubject\" [name]=\"'transform data'|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=\"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>{{'transformed data'|firstUppercaseLocalize}}</div>\n                <relation-node-output [parentCoordiantes]=\"nodePosition\" [zoomLevel]=\"zoomLevel\" name=\"transformedData\" [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>{{'code'|firstUppercaseLocalize}}</span>\n    </button>\n</div>" }]
        }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1.TitledDialogService }] });
//# sourceMappingURL=transformDataNode.component.js.map