import { __decorate } from "tslib";
import { Component, Input } from '@angular/core';
import { FormControl } from '@angular/forms';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { startWith } from 'rxjs/operators';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/forms";
import * as i3 from "@aztrix/icons";
import * as i4 from "@angular/material/form-field";
import * as i5 from "@angular/material/input";
import * as i6 from "@aztrix/helpers";
let DomainEditComponent = class DomainEditComponent {
    constructor() {
        this._regexInvalidChars = /[^a-zA-Z0-9.-]/g;
        this._regexHttps = /^https:\/\//;
    }
    ngOnChanges(changes) {
        if (changes.form && this.form) {
            this.form.valueChanges
                .pipe(untilDestroyed(this), startWith(this.form.value))
                .subscribe((value) => {
                if (value === '') {
                    this.form.setValue(undefined);
                }
                else if (this._regexHttps.test(value)) {
                    this.form.setValue(value.replace(this._regexHttps, ''));
                }
                else if (this._regexInvalidChars.test(value)) {
                    this.form.setValue(value.replace(this._regexInvalidChars, ''));
                }
            });
        }
    }
    get errors() {
        return this.form?.errors || {};
    }
    errorTranslationKey(errorType) {
        switch (errorType) {
            case 'domain-in-use':
                return 'page.domain.validation.in-use';
            case 'required':
                return 'property.validation.required';
            default:
                return undefined;
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: DomainEditComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.11", type: DomainEditComponent, selector: "ax-domain-edit", inputs: { form: "form", label: "label", postfix: "postfix" }, usesOnChanges: true, ngImport: i0, template: "<mat-form-field class=\"c-input input\" appearance=\"outline\" floatLabel=\"always\">\n  <mat-label *ngIf=\"label\">{{ label }}</mat-label>\n  <div class=\"input-field\">\n    <input matInput [type]=\"'text'\" [formControl]=\"form\" />\n    <span *ngIf=\"postfix\" class=\"custom-prefix\">\n      {{ postfix }}\n    </span>\n  </div>\n  <mat-error *ngFor=\"let error of errors | keyvalue\">\n    <ax-icon name=\"alert-circle\"></ax-icon>\n    <span>{{\n      errorTranslationKey(error.key)\n        | translate\n          : (error.key === 'required'\n              ? {propertyType: ('label.domain.url' | translate)}\n              : error.value)\n    }}</span>\n  </mat-error>\n  <mat-hint align=\"end\">\n    <a target=\"_blank\" href=\"https://aztrix.atlassian.net/l/c/pdeTsGEe\">{{\n      'page.domain.hint' | translate\n    }}</a>\n  </mat-hint>\n</mat-form-field>\n", styles: [":host{display:block}.input-field{display:flex}.custom-prefix{white-space:nowrap;color:var(--font-color)}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.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: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i3.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "component", type: i4.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i4.MatLabel, selector: "mat-label" }, { kind: "directive", type: i4.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "directive", type: i4.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i5.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "pipe", type: i1.KeyValuePipe, name: "keyvalue" }, { kind: "pipe", type: i6.TranslatePipe, name: "translate" }] }); }
};
DomainEditComponent = __decorate([
    UntilDestroy()
], DomainEditComponent);
export { DomainEditComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: DomainEditComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-domain-edit', template: "<mat-form-field class=\"c-input input\" appearance=\"outline\" floatLabel=\"always\">\n  <mat-label *ngIf=\"label\">{{ label }}</mat-label>\n  <div class=\"input-field\">\n    <input matInput [type]=\"'text'\" [formControl]=\"form\" />\n    <span *ngIf=\"postfix\" class=\"custom-prefix\">\n      {{ postfix }}\n    </span>\n  </div>\n  <mat-error *ngFor=\"let error of errors | keyvalue\">\n    <ax-icon name=\"alert-circle\"></ax-icon>\n    <span>{{\n      errorTranslationKey(error.key)\n        | translate\n          : (error.key === 'required'\n              ? {propertyType: ('label.domain.url' | translate)}\n              : error.value)\n    }}</span>\n  </mat-error>\n  <mat-hint align=\"end\">\n    <a target=\"_blank\" href=\"https://aztrix.atlassian.net/l/c/pdeTsGEe\">{{\n      'page.domain.hint' | translate\n    }}</a>\n  </mat-hint>\n</mat-form-field>\n", styles: [":host{display:block}.input-field{display:flex}.custom-prefix{white-space:nowrap;color:var(--font-color)}\n"] }]
        }], propDecorators: { form: [{
                type: Input
            }], label: [{
                type: Input
            }], postfix: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 