import { __awaiter } from "tslib";
import { Component, ChangeDetectionStrategy, Inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms';
import { MatDialogModule } from '@angular/material/dialog';
import { FirstUppercaseLocalizeSAPipe } from '@anglr/common';
import { TitledDialogService, TITLED_DIALOG_DATA } from '@anglr/common/material';
import { FormModelBuilder } from '@anglr/common/forms';
import { CodeEditorDialogComponent, getJson, JsonLanguageModel } from '@anglr/dynamic';
import { extend, isPresent } from '@jscrpt/common';
import { lastValueFrom } from '@jscrpt/common/rxjs';
import { ComponentEndpointModel } from './configureNodeEndpoint.model';
import * as i0 from "@angular/core";
import * as i1 from "@anglr/common/material";
import * as i2 from "@anglr/common/forms";
import * as i3 from "@angular/forms";
import * as i4 from "@angular/material/dialog";
import * as i5 from "@angular/common";
/**
 * Component used for configuring node endpoint
 */
export class ConfigureNodeEndpointSAComponent {
    //######################### constructor #########################
    constructor(data, dialog, formModelBuilder) {
        this.data = data;
        this.dialog = dialog;
        this.form = formModelBuilder.build(new ComponentEndpointModel(data));
        this.form.valueChanges.subscribe(value => extend(data, value));
    }
    //######################### protected methods - template bindings #########################
    /**
     * Shows code editor
     */
    showCodeEditor() {
        return __awaiter(this, void 0, void 0, function* () {
            const content = isPresent(this.data.defaultValue) ? JSON.stringify(this.data.defaultValue, null, 4) : '';
            const result = yield lastValueFrom(this.dialog.open(CodeEditorDialogComponent, {
                title: 'Code editor',
                width: '75vw',
                height: '75vh',
                data: {
                    content,
                    languageModel: JsonLanguageModel,
                }
            }).afterClosed());
            if (isPresent(result)) {
                this.data.defaultValue = getJson(result.content);
            }
        });
    }
}
ConfigureNodeEndpointSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ConfigureNodeEndpointSAComponent, deps: [{ token: TITLED_DIALOG_DATA }, { token: i1.TitledDialogService }, { token: i2.FormModelBuilder }], target: i0.ɵɵFactoryTarget.Component });
ConfigureNodeEndpointSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: ConfigureNodeEndpointSAComponent, isStandalone: true, selector: "configure-node-endpoint", providers: [
        FormModelBuilder,
    ], ngImport: i0, template: "<div [formGroup]=\"form\">\n    <div class=\"dynamic-form-group dynamic-margin-bottom-extra-small\">\n        <label class=\"dynamic-control-label dynamic-text-uppercase\">{{'name'|firstUppercaseLocalize}}</label>\n        <input type=\"text\" class=\"dynamic-form-control\" formControlName=\"name\">\n    </div>\n\n    <div class=\"dynamic-form-group dynamic-margin-bottom-extra-small\" *ngIf=\"data.allowSkipInit\">\n        <label class=\"dynamic-control-label dynamic-text-uppercase\"><input type=\"checkbox\" formControlName=\"skipInit\"> {{'skip init'|firstUppercaseLocalize}} </label>\n    </div>\n\n    <div class=\"dynamic-flex-column dynamic-margin-bottom-extra-small\" *ngIf=\"!data.noDefaultValue\">\n        <button type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-align-self-center\" (click)=\"showCodeEditor()\">\n            <span>{{'default value'|firstUppercaseLocalize}}</span>\n        </button>\n    </div>\n</div>\n\n<div class=\"dynamic-flex-row dynamic-flex-end dynamic-action-buttons\">\n    <button type=\"button\" class=\"dynamic-btn dynamic-btn-info dynamic-margin-right-extra-small\" [mat-dialog-close]=\"null\">\n        <span>{{'cancel'|firstUppercaseLocalize}}</span>\n    </button>\n\n    <button type=\"button\" class=\"dynamic-btn dynamic-btn-primary\" [mat-dialog-close]=\"true\">\n        <span>{{'ok'|firstUppercaseLocalize}}</span>\n    </button>\n</div>", dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "ngmodule", type: MatDialogModule }, { kind: "directive", type: i4.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["aria-label", "type", "mat-dialog-close", "matDialogClose"], exportAs: ["matDialogClose"] }, { kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: FirstUppercaseLocalizeSAPipe, name: "firstUppercaseLocalize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ConfigureNodeEndpointSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'configure-node-endpoint', standalone: true, imports: [
                        ReactiveFormsModule,
                        MatDialogModule,
                        CommonModule,
                        FirstUppercaseLocalizeSAPipe,
                    ], providers: [
                        FormModelBuilder,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [formGroup]=\"form\">\n    <div class=\"dynamic-form-group dynamic-margin-bottom-extra-small\">\n        <label class=\"dynamic-control-label dynamic-text-uppercase\">{{'name'|firstUppercaseLocalize}}</label>\n        <input type=\"text\" class=\"dynamic-form-control\" formControlName=\"name\">\n    </div>\n\n    <div class=\"dynamic-form-group dynamic-margin-bottom-extra-small\" *ngIf=\"data.allowSkipInit\">\n        <label class=\"dynamic-control-label dynamic-text-uppercase\"><input type=\"checkbox\" formControlName=\"skipInit\"> {{'skip init'|firstUppercaseLocalize}} </label>\n    </div>\n\n    <div class=\"dynamic-flex-column dynamic-margin-bottom-extra-small\" *ngIf=\"!data.noDefaultValue\">\n        <button type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-align-self-center\" (click)=\"showCodeEditor()\">\n            <span>{{'default value'|firstUppercaseLocalize}}</span>\n        </button>\n    </div>\n</div>\n\n<div class=\"dynamic-flex-row dynamic-flex-end dynamic-action-buttons\">\n    <button type=\"button\" class=\"dynamic-btn dynamic-btn-info dynamic-margin-right-extra-small\" [mat-dialog-close]=\"null\">\n        <span>{{'cancel'|firstUppercaseLocalize}}</span>\n    </button>\n\n    <button type=\"button\" class=\"dynamic-btn dynamic-btn-primary\" [mat-dialog-close]=\"true\">\n        <span>{{'ok'|firstUppercaseLocalize}}</span>\n    </button>\n</div>" }]
        }], ctorParameters: () => [{ type: undefined, decorators: [{
                    type: Inject,
                    args: [TITLED_DIALOG_DATA]
                }] }, { type: i1.TitledDialogService }, { type: i2.FormModelBuilder }] });
//# sourceMappingURL=configureNodeEndpoint.component.js.map