import { Component, Input } from '@angular/core';
import { FormBuilder, Validators, } from '@angular/forms';
import { ModalController } from '@ionic/angular';
import { getFormFieldOrError } from '../utility';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@ionic/angular";
export class TapValueEditorModalComponent {
    constructor(formBuilder, modalController) {
        this.modalController = modalController;
        this.inputOptions = {
            type: 'text',
        };
        this.form = formBuilder.group({
            field: [
                '',
                [
                    Validators.required,
                    Validators.max(this.inputOptions.max),
                    Validators.maxLength(this.inputOptions.maxLength),
                    Validators.min(this.inputOptions.min),
                    Validators.minLength(this.inputOptions.minLength),
                ],
            ],
        });
        this.field = getFormFieldOrError(this.form, 'field');
    }
    set value(v) {
        this.field.setValue(v, { emitEvent: false });
    }
    ngOnInit() { }
    onSubmit() {
        if (this.form.valid) {
            console.log('Result', this.field.value);
            this.modalController.dismiss({
                value: this.field.value,
            }, 'submit');
        }
    }
    cancel() {
        this.modalController.dismiss();
    }
}
/** @nocollapse */ TapValueEditorModalComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapValueEditorModalComponent, deps: [{ token: i1.FormBuilder }, { token: i2.ModalController }], target: i0.ɵɵFactoryTarget.Component });
/** @nocollapse */ TapValueEditorModalComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: TapValueEditorModalComponent, selector: "tap-value-editor-modal", inputs: { inputOptions: "inputOptions", value: "value" }, ngImport: i0, template: "<ion-header>\n  <ion-toolbar color=\"primary\">\n    <ion-buttons slot=\"start\">\n      <ion-button fill=\"clear\" (click)=\"cancel()\">\n        <ion-icon name=\"arrow-back-outline\"></ion-icon>\n      </ion-button>\n    </ion-buttons>\n    <ion-title>Edition</ion-title>\n  </ion-toolbar>\n</ion-header>\n<ion-content>\n  <ion-grid>\n    <ion-row justify-content-center align-items-center>\n      <div style=\"margin: auto\">\n        <form\n          (ngSubmit)=\"onSubmit()\"\n          [formGroup]=\"form\"\n          (keydown.enter)=\"onSubmit()\"\n        >\n          <ion-list lines=\"none\">\n            <ion-item>\n              <ion-label position=\"floating\"> Value </ion-label>\n              <ion-input\n                [pattern]=\"inputOptions.pattern\"\n                [placeholder]=\"inputOptions.placeholder\"\n                [type]=\"inputOptions.type\"\n                [formControl]=\"field\"\n                [value]=\"value\"\n              >\n              </ion-input>\n            </ion-item>\n            <ion-item>\n              <ion-buttons slot=\"end\">\n                <ion-button\n                  color=\"primary\"\n                  type=\"submit\"\n                  [disabled]=\"!form.valid\"\n                  (click)=\"onSubmit()\"\n                >\n                  Submit\n                </ion-button>\n              </ion-buttons>\n            </ion-item>\n          </ion-list>\n        </form>\n      </div>\n    </ion-row>\n  </ion-grid>\n</ion-content>\n", styles: ["ion-grid{height:100%}ion-grid>ion-row{height:100%}ion-grid>ion-row>div{margin:auto}ion-input{font-size:2em}\n"], dependencies: [{ kind: "component", type: i2.IonButton, selector: "ion-button", inputs: ["buttonType", "color", "disabled", "download", "expand", "fill", "form", "href", "mode", "rel", "routerAnimation", "routerDirection", "shape", "size", "strong", "target", "type"] }, { kind: "component", type: i2.IonButtons, selector: "ion-buttons", inputs: ["collapse"] }, { kind: "component", type: i2.IonContent, selector: "ion-content", inputs: ["color", "forceOverscroll", "fullscreen", "scrollEvents", "scrollX", "scrollY"] }, { kind: "component", type: i2.IonGrid, selector: "ion-grid", inputs: ["fixed"] }, { kind: "component", type: i2.IonHeader, selector: "ion-header", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: i2.IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "component", type: i2.IonInput, selector: "ion-input", inputs: ["accept", "autocapitalize", "autocomplete", "autocorrect", "autofocus", "clearInput", "clearOnEdit", "color", "debounce", "disabled", "enterkeyhint", "inputmode", "max", "maxlength", "min", "minlength", "mode", "multiple", "name", "pattern", "placeholder", "readonly", "required", "size", "spellcheck", "step", "type", "value"] }, { kind: "component", type: i2.IonItem, selector: "ion-item", inputs: ["button", "color", "counter", "counterFormatter", "detail", "detailIcon", "disabled", "download", "fill", "href", "lines", "mode", "rel", "routerAnimation", "routerDirection", "shape", "target", "type"] }, { kind: "component", type: i2.IonLabel, selector: "ion-label", inputs: ["color", "mode", "position"] }, { kind: "component", type: i2.IonList, selector: "ion-list", inputs: ["inset", "lines", "mode"] }, { kind: "component", type: i2.IonRow, selector: "ion-row" }, { kind: "component", type: i2.IonTitle, selector: "ion-title", inputs: ["color", "size"] }, { kind: "component", type: i2.IonToolbar, selector: "ion-toolbar", inputs: ["color", "mode"] }, { kind: "directive", type: i2.TextValueAccessor, selector: "ion-input:not([type=number]),ion-textarea,ion-searchbar" }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.PatternValidator, selector: "[pattern][formControlName],[pattern][formControl],[pattern][ngModel]", inputs: ["pattern"] }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapValueEditorModalComponent, decorators: [{
            type: Component,
            args: [{ selector: 'tap-value-editor-modal', template: "<ion-header>\n  <ion-toolbar color=\"primary\">\n    <ion-buttons slot=\"start\">\n      <ion-button fill=\"clear\" (click)=\"cancel()\">\n        <ion-icon name=\"arrow-back-outline\"></ion-icon>\n      </ion-button>\n    </ion-buttons>\n    <ion-title>Edition</ion-title>\n  </ion-toolbar>\n</ion-header>\n<ion-content>\n  <ion-grid>\n    <ion-row justify-content-center align-items-center>\n      <div style=\"margin: auto\">\n        <form\n          (ngSubmit)=\"onSubmit()\"\n          [formGroup]=\"form\"\n          (keydown.enter)=\"onSubmit()\"\n        >\n          <ion-list lines=\"none\">\n            <ion-item>\n              <ion-label position=\"floating\"> Value </ion-label>\n              <ion-input\n                [pattern]=\"inputOptions.pattern\"\n                [placeholder]=\"inputOptions.placeholder\"\n                [type]=\"inputOptions.type\"\n                [formControl]=\"field\"\n                [value]=\"value\"\n              >\n              </ion-input>\n            </ion-item>\n            <ion-item>\n              <ion-buttons slot=\"end\">\n                <ion-button\n                  color=\"primary\"\n                  type=\"submit\"\n                  [disabled]=\"!form.valid\"\n                  (click)=\"onSubmit()\"\n                >\n                  Submit\n                </ion-button>\n              </ion-buttons>\n            </ion-item>\n          </ion-list>\n        </form>\n      </div>\n    </ion-row>\n  </ion-grid>\n</ion-content>\n", styles: ["ion-grid{height:100%}ion-grid>ion-row{height:100%}ion-grid>ion-row>div{margin:auto}ion-input{font-size:2em}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: i2.ModalController }]; }, propDecorators: { inputOptions: [{
                type: Input
            }], value: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 