import { __decorate } from 'tslib';
import * as i0 from '@angular/core';
import { Component, Input, NgModule } from '@angular/core';
import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy';
import { startWith } from 'rxjs/operators';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';
import * as i3 from '@aztrix/icons';
import { IconsModule } from '@aztrix/icons';
import * as i4 from '@angular/material/form-field';
import { MatFormFieldModule } from '@angular/material/form-field';
import * as i5 from '@angular/material/input';
import { MatInputModule } from '@angular/material/input';
import * as i6 from '@aztrix/helpers';
import { HelperPipesModule } from '@aztrix/helpers';
import { AutofocusModule } from '@aztrix/components/autofocus';

let DomainEditComponent = class DomainEditComponent {
    constructor() {
        this.readonly = false;
        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.12", ngImport: i0, type: DomainEditComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.12", type: DomainEditComponent, selector: "ax-domain-edit", inputs: { form: "form", label: "label", postfix: "postfix", readonly: "readonly", howToLink: "howToLink" }, usesOnChanges: true, ngImport: i0, template: "<mat-form-field\n  class=\"c-input input\"\n  appearance=\"outline\"\n  [ngClass]=\"{readonly: readonly}\"\n  floatLabel=\"always\"\n>\n  <mat-label *ngIf=\"label\">{{ label }}</mat-label>\n  <div class=\"input-field\">\n    @if (form) {\n      <input matInput [type]=\"'text'\" [formControl]=\"form\" [readonly]=\"readonly\" />\n    }\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]=\"howToLink\">{{ 'page.domain.hint' | translate }}</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)}.readonly{pointer-events:none}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { 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);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DomainEditComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-domain-edit', template: "<mat-form-field\n  class=\"c-input input\"\n  appearance=\"outline\"\n  [ngClass]=\"{readonly: readonly}\"\n  floatLabel=\"always\"\n>\n  <mat-label *ngIf=\"label\">{{ label }}</mat-label>\n  <div class=\"input-field\">\n    @if (form) {\n      <input matInput [type]=\"'text'\" [formControl]=\"form\" [readonly]=\"readonly\" />\n    }\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]=\"howToLink\">{{ 'page.domain.hint' | translate }}</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)}.readonly{pointer-events:none}\n"] }]
        }], propDecorators: { form: [{
                type: Input
            }], label: [{
                type: Input
            }], postfix: [{
                type: Input
            }], readonly: [{
                type: Input
            }], howToLink: [{
                type: Input
            }] } });

class DomainEditModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DomainEditModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: DomainEditModule, declarations: [DomainEditComponent], imports: [CommonModule,
            ReactiveFormsModule,
            IconsModule,
            MatFormFieldModule,
            MatInputModule,
            HelperPipesModule,
            AutofocusModule], exports: [DomainEditComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DomainEditModule, imports: [CommonModule,
            ReactiveFormsModule,
            IconsModule,
            MatFormFieldModule,
            MatInputModule,
            HelperPipesModule,
            AutofocusModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DomainEditModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [DomainEditComponent],
                    imports: [
                        CommonModule,
                        ReactiveFormsModule,
                        IconsModule,
                        MatFormFieldModule,
                        MatInputModule,
                        HelperPipesModule,
                        AutofocusModule,
                    ],
                    exports: [DomainEditComponent],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { DomainEditComponent, DomainEditModule };
//# sourceMappingURL=aztrix-components-domain-edit.mjs.map
