import { NgIf } from '@angular/common';
import { Component, Input } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { CoreModule } from '@c8y/ngx-components';
import { gettext } from '@c8y/ngx-components/gettext';
import { BsModalRef } from 'ngx-bootstrap/modal';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "ngx-bootstrap/modal";
import * as i3 from "@c8y/ngx-components";
import * as i4 from "@angular/common";
export class VncCredentialsPromptComponent {
    constructor(formBuilder, modalRef) {
        this.formBuilder = formBuilder;
        this.modalRef = modalRef;
        this.title = gettext('VNC credentials');
        this.types = [];
        this.result = new Promise((resolve, reject) => {
            this._resolve = resolve;
            this._reject = reject;
        });
        this.showUsername = false;
        this.form = this.initForm();
    }
    ngOnInit() {
        this.showUsername = this.types.includes('username');
        this.form = this.initForm();
    }
    initForm() {
        return this.formBuilder.group({
            username: [undefined, this.showUsername ? [Validators.required] : []],
            password: [undefined, [Validators.required]]
        });
    }
    cancel() {
        this._reject();
    }
    save() {
        this._resolve(this.form.value);
    }
    submit() {
        if (!this.form.valid) {
            return;
        }
        this.modalRef.hide();
        this.save();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: VncCredentialsPromptComponent, deps: [{ token: i1.FormBuilder }, { token: i2.BsModalRef }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: VncCredentialsPromptComponent, isStandalone: true, selector: "c8y-vnc-credentials-prompt", inputs: { types: "types" }, 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]=\"'key'\"></span>\n  </ng-container>\n  <form\n    class=\"p-24\"\n    [formGroup]=\"form\"\n    (submit)=\"submit()\"\n  >\n    <c8y-form-group *ngIf=\"showUsername\">\n      <label\n        for=\"username\"\n        translate\n      >\n        Username\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"username\"\n        name=\"username\"\n        type=\"text\"\n        [placeholder]=\"'e.g. {{ example }}' | translate: { example: 'admin' }\"\n        formControlName=\"username\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"password\"\n        translate\n      >\n        Password\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"password\"\n        name=\"password\"\n        type=\"password\"\n        formControlName=\"password\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <button type=\"submit\" class=\"hidden\">hidden submit</button>\n  </form>\n</c8y-modal>\n", dependencies: [{ kind: "ngmodule", type: CoreModule }, { kind: "directive", type: i3.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "pipe", type: i3.C8yTranslatePipe, name: "translate" }, { kind: "directive", type: i3.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.ModalComponent, selector: "c8y-modal", inputs: ["disabled", "close", "dismiss", "title", "body", "customFooter", "headerClasses", "labels"], outputs: ["onDismiss", "onClose"] }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { 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.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "component", type: i3.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "component", type: i3.MessagesComponent, selector: "c8y-messages", inputs: ["show", "defaults", "helpMessage"] }, { kind: "directive", type: i3.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: VncCredentialsPromptComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-vnc-credentials-prompt', standalone: true, imports: [CoreModule, NgIf], 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]=\"'key'\"></span>\n  </ng-container>\n  <form\n    class=\"p-24\"\n    [formGroup]=\"form\"\n    (submit)=\"submit()\"\n  >\n    <c8y-form-group *ngIf=\"showUsername\">\n      <label\n        for=\"username\"\n        translate\n      >\n        Username\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"username\"\n        name=\"username\"\n        type=\"text\"\n        [placeholder]=\"'e.g. {{ example }}' | translate: { example: 'admin' }\"\n        formControlName=\"username\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <c8y-form-group>\n      <label\n        for=\"password\"\n        translate\n      >\n        Password\n      </label>\n      <input\n        class=\"form-control\"\n        id=\"password\"\n        name=\"password\"\n        type=\"password\"\n        formControlName=\"password\"\n      />\n      <c8y-messages></c8y-messages>\n    </c8y-form-group>\n\n    <button type=\"submit\" class=\"hidden\">hidden submit</button>\n  </form>\n</c8y-modal>\n" }]
        }], ctorParameters: () => [{ type: i1.FormBuilder }, { type: i2.BsModalRef }], propDecorators: { types: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 