import { Component } from '@angular/core';
import { ControlContainer, NgForm } from '@angular/forms';
import { FVAbstractControl } from '../../../shared/abstract-control.component';
import { ProcessService } from '../../../../services/process.service';
export class FVControlsPhoneFieldComponent extends FVAbstractControl {
    constructor(process) {
        super(process);
        this.nonNumberCharRegEx = new RegExp("(?<=.{1})[^0-9]", "gi");
        this.firstPhoneCharRegEx = new RegExp("[^+0-9]", "gi");
    }
    ngAfterViewInit() {
        super.AfterViewInit();
        this.formControl.valueChanges.subscribe(value => this.parsePhoneNumber(value));
    }
    parsePhoneNumber(value) {
        if (value) {
            const phoneNumber = value.replace(this.nonNumberCharRegEx, '')
                .replace(this.firstPhoneCharRegEx, '');
            this.formControl.setValue(phoneNumber, { onlySelf: true, emitEvent: false, emitModelToViewChange: true, emitViewToModelChange: true });
        }
    }
}
FVControlsPhoneFieldComponent.decorators = [
    { type: Component, args: [{
                selector: 'fv-controls-phone-field',
                template: "<div *ngIf=\"control\" class=\"controlBox\" [attr.id]=\"'control-' + control.referenceName\">\n  <i *ngIf=\"buttonsDebug\" (click)=\"debugStatus =! debugStatus\" class=\"fa fa-stethoscope\"></i>\n  <ng-container *ngIf=\"!hideLabel\">\n    <span class=\"controlName\" [attr.id]=\"'label-' + control.referenceName\">{{ control?.label | ltranslate }}</span>\n    <span *ngIf=\"control?.isRequired\" class=\"required\">*</span>\n    <i *ngIf=\"tooltip\" class=\"fa fa-question-circle\" [tooltip]=\"tooltip\" placement=\"top\"></i>\n  </ng-container>\n  <div *ngIf=\"debugStatus\" [innerText]=\"toString()\"></div>\n  <div class=\"input-group\">\n    <input type=\"tel\" [attr.id]=\"'input-' + control.referenceName\" class=\"form-control\" [name]=\"control?.key\"\n      ngModel [disabled]=\"disabled\" [readonly]=\"isReadOnly ? true : null\" [required]=\"control?.isRequired ? true : null\"\n      [attr.maxlength]=\"control?.size || defaultControlSize\" [placeholder]=\"(control.placeholder || '') | ltranslate\"\n      [pattern]=\"control.pattern\" >\n    <fv-controls-validator *ngIf=\"group?.controls[control.key]\" [FVFormControl]=\"group?.controls[control.key]\" [group]=\"group\"\n      [control]=\"control\" [task]=\"task\" [tabIndex]=\"tabIndex\"></fv-controls-validator>\n</div>",
                viewProviders: [{ provide: ControlContainer, useExisting: NgForm }],
                styles: [".col{display:inline-flex;flex-basis:0;flex-grow:1;max-width:100%;min-width:50%}.col fv-form-tab{display:block;padding:0 5px;width:100%}.col fv-form-tab .controls-row{margin:0;padding:0;width:100%}.col fv-form-tab div{max-width:100%}.columns-0,.columns-1{max-width:100%;min-width:100%;width:100%}.columns-2{max-width:50%;min-width:50%;width:50%}.columns-3{max-width:33.33%;min-width:33.33%;width:33.33%}.columns-4{max-width:25%;min-width:25%;width:25%}.controlBox .input-group{display:inline-flex;margin-top:5px;width:100%}.controlBox>.input-group>button:not(.input-group-addon),.controlBox>.input-group>input,.controlBox>.input-group>select{height:40px!important;padding:10px;width:100%}.controlBox .input-group button.input-group-addon{height:40px;position:relative;width:35px}.controlBox .input-group span.controlName{color:red}.controlBox .input-group button.input-group-addon i{bottom:0;left:0;position:absolute;right:0;top:10px}.has-text-centered,.table,.table thead th{text-align:center}.gridForm{margin:0 0 10px;padding:0;width:100%}.gridForm .input-group>.form-control{border-radius:unset;margin-right:10px;max-width:50%;min-height:45px;min-width:80px}.gridForm .input-group>.addon{background:none;border:none;color:#36c}.grid-table tbody>tr>td{vertical-align:middle}span.required{color:red}form:not(.ng-untouched) .ng-invalid{border:1px solid red}form:not(.ng-untouched) .ng-invalid.input-group-addon{border-left:none!important}span.error-block{color:red}@media screen and (max-width:426px){.columns-2,.columns-3,.columns-4{max-width:100%;min-width:100%;width:100%}}.tree:last-of-type(.accordion){margin:0}select:disabled{background:#eee}navigator-bot,navigator-top{display:flex}fv-menu-folder:last-of-type>accordion:last-of-type{margin:0;padding:0}.button-group>button:not(:last-child):not(:first-child){margin-left:0!important;margin-right:0!important;padding-left:0!important;padding-right:0!important}.fv_container,.fv_container>*,navigator-after,navigator-before{all:inherit!important;padding:0!important}.lookup-form .gridInputs{width:100%}.lookup-form .gridInputs select{width:40%}.lookup-form .gridInputs input{width:60%}.lookup-form .gridInputs,.lookup-form .gridInputs input,.lookup-form .gridInputs select{max-width:100%}.noMarginY{margin-bottom:0!important;margin-top:0!important}.placeholder,ng-select input:-moz-placeholder,ng-select input:-ms-input-placeholder,ng-select input:-webkit-input-placeholder,ng-select input:placeholder{color:#a9a9a9}select-dropdown>div{position:relative!important;top:0!important}select-dropdown div.options{text-align:left}bs-datepicker-navigation-view{display:block;text-align:center;width:100%}.bs-datepicker-head .previous{float:left}.bs-datepicker-head .next{float:right}textarea{min-height:45px;min-width:100%}.modal-dialog>.modal-content{max-height:100vh}.modal-content>.modal-body{max-height:85vh;overflow-y:auto;padding-bottom:0}.modal-content fv-navigator.nav-bottom{background-color:hsla(0,0%,99.2%,.62);border-bottom-left-radius:10px;border-bottom-right-radius:10px;bottom:0;display:block;height:50px;left:0;margin:0 2px;padding:0 3rem;position:-webkit-sticky;position:sticky;right:0;z-index:999}.modal-content fv-navigator .docked-buttons{width:auto}.modal-content fv-navigator .btn-col:not(.bottom){max-width:unset;padding:6px!important}.modal-dialog .modal-header .pull-right span{font-size:inherit!important}.basic-commands button{margin-right:5px;text-transform:capitalize}"]
            },] }
];
FVControlsPhoneFieldComponent.ctorParameters = () => [
    { type: ProcessService }
];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGhvbmUtZmllbGQuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2FwcC9jb21wb25lbnRzL3JlbmRlcmVyL2NvbnRyb2xzL1Bob25lRmllbGQvcGhvbmUtZmllbGQuY29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxTQUFTLEVBQWlCLE1BQU0sZUFBZSxDQUFDO0FBQ3pELE9BQU8sRUFBRS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