import { Component } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { CoreModule, gettext } from '@c8y/ngx-components';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@c8y/ngx-components";
export class RemoteAccessBasicEndpointModalComponent {
    constructor(formBuilder) {
        this.formBuilder = formBuilder;
        this.title = gettext('Remote access endpoint');
        this.result = new Promise((resolve, reject) => {
            this._resolve = resolve;
            this._reject = reject;
        });
        this.form = this.initForm();
    }
    ngOnInit() {
        if (this.currentValue) {
            const { credentials, ...rest } = this.currentValue;
            const credentialsType = credentials?.type || 'NONE';
            const patchedValue = { ...rest, credentialsType };
            this.form.patchValue(patchedValue);
        }
    }
    initForm() {
        return this.formBuilder.group({
            id: ['', []],
            name: ['', [Validators.required, Validators.minLength(1)]],
            hostname: ['', [Validators.required, Validators.minLength(1)]],
            port: [undefined, [Validators.required, Validators.min(1), Validators.max(65535)]],
            protocol: ['', [Validators.required, Validators.minLength(1)]],
            credentialsType: ['NONE', [Validators.required]],
            attrs: [undefined]
        });
    }
    cancel() {
        this._reject();
    }
    save() {
        this._resolve(this.form.value);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: RemoteAccessBasicEndpointModalComponent, deps: [{ token: i1.FormBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: RemoteAccessBasicEndpointModalComponent, isStandalone: true, selector: "c8y-remote-access-basic-endpoint-modal", ngImport: i0, template: "<c8y-modal\n  [title]=\"title\"\n  [headerClasses]=\"'dialog-header'\"\n  (onDismiss)=\"cancel()\"\n  (onClose)=\"save()\"\n  [disabled]=\"form.invalid\"\n  [labels]=\"{ cancel: 'Cancel', ok: 'Save' }\"\n>\n  <ng-container c8y-modal-title>\n    <span [c8yIcon]=\"'laptop'\"></span>\n  </ng-container>\n  <div\n    class=\"p-24\"\n    [formGroup]=\"form\"\n  >\n    <c8y-form-group>\n      <label\n        for=\"name\"\n        translate\n      >\n        Name\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"name\"\n        [placeholder]=\"'e.g. {{ example }}' | translate : { example: 'My remote access endpoint' }\"\n        name=\"name\"\n        type=\"text\"\n        formControlName=\"name\"\n        [attr.data-cy]=\"'remoteAccessEndpointModal--name'\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"protocol\"\n        translate\n      >\n        Protocol\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"protocol\"\n        readonly\n        name=\"protocol\"\n        type=\"text\"\n        formControlName=\"protocol\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"hostname\"\n        translate\n      >\n        Host\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"hostname\"\n        placeholder=\"{{'e.g. {{ example }}' | translate : { example: '127.0.0.1' } }}\"\n        name=\"hostname\"\n        type=\"text\"\n        formControlName=\"hostname\"\n        [attr.data-cy]=\"'remoteAccessEndpointModal--hostname'\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"port\"\n        translate\n      >\n        Port\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"port\"\n        placeholder=\"{{'e.g. {{ example }}' | translate : { example: '8080' } }}\"\n        name=\"port\"\n        type=\"number\"\n        formControlName=\"port\"\n        [attr.data-cy]=\"'remoteAccessEndpointModal--port'\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n  </div>\n</c8y-modal>\n", dependencies: [{ kind: "ngmodule", type: CoreModule }, { kind: "directive", type: i2.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }, { kind: "directive", type: i2.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "component", type: i2.ModalComponent, selector: "c8y-modal", inputs: ["disabled", "close", "dismiss", "title", "body", "customFooter", "headerClasses", "labels"], outputs: ["onDismiss", "onClose"] }, { kind: "directive", type: i1.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: i1.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "component", type: i2.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "component", type: i2.MessagesComponent, selector: "c8y-messages", inputs: ["show", "defaults", "helpMessage"] }, { kind: "directive", type: i2.RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: RemoteAccessBasicEndpointModalComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-remote-access-basic-endpoint-modal', standalone: true, imports: [CoreModule], template: "<c8y-modal\n  [title]=\"title\"\n  [headerClasses]=\"'dialog-header'\"\n  (onDismiss)=\"cancel()\"\n  (onClose)=\"save()\"\n  [disabled]=\"form.invalid\"\n  [labels]=\"{ cancel: 'Cancel', ok: 'Save' }\"\n>\n  <ng-container c8y-modal-title>\n    <span [c8yIcon]=\"'laptop'\"></span>\n  </ng-container>\n  <div\n    class=\"p-24\"\n    [formGroup]=\"form\"\n  >\n    <c8y-form-group>\n      <label\n        for=\"name\"\n        translate\n      >\n        Name\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"name\"\n        [placeholder]=\"'e.g. {{ example }}' | translate : { example: 'My remote access endpoint' }\"\n        name=\"name\"\n        type=\"text\"\n        formControlName=\"name\"\n        [attr.data-cy]=\"'remoteAccessEndpointModal--name'\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"protocol\"\n        translate\n      >\n        Protocol\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"protocol\"\n        readonly\n        name=\"protocol\"\n        type=\"text\"\n        formControlName=\"protocol\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"hostname\"\n        translate\n      >\n        Host\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"hostname\"\n        placeholder=\"{{'e.g. {{ example }}' | translate : { example: '127.0.0.1' } }}\"\n        name=\"hostname\"\n        type=\"text\"\n        formControlName=\"hostname\"\n        [attr.data-cy]=\"'remoteAccessEndpointModal--hostname'\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"port\"\n        translate\n      >\n        Port\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"port\"\n        placeholder=\"{{'e.g. {{ example }}' | translate : { example: '8080' } }}\"\n        name=\"port\"\n        type=\"number\"\n        formControlName=\"port\"\n        [attr.data-cy]=\"'remoteAccessEndpointModal--port'\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n  </div>\n</c8y-modal>\n" }]
        }], ctorParameters: () => [{ type: i1.FormBuilder }] });
//# sourceMappingURL=data:application/json;base64, 