import * as i0 from '@angular/core';
import { inject, Component, Input } from '@angular/core';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import { MatInputModule } from '@angular/material/input';
import { TranslateService } from '@ngx-translate/core';
import * as i2 from '@angular/material/form-field';

const ERROR_MESSAGES = {
    required: (params) => `${params?.label} ${params?.language === 'en' ? 'is required' : 'مطلوب'}`,
    minlength: (params) => `${params?.label} ${params?.language === "en" ? "should contain at least" : "يجب ان يكون علي الاقل"} ${params?.controllerErrors?.requiredLength} ${params?.language === "en" ? "characters" : "حروف"}`,
    maxlength: (params) => `This field should not exceed ${params?.controllerErrors?.requiredLength} characters`,
    email: (params) => `${params?.language === 'en' ? 'Invalid email' : 'بريد إلكتروني غير صالح'}`,
    phone: (params) => `${params?.language === 'en' ? 'Invalid phone number' : 'رقم هاتف غير صالح'}`,
    number: (params) => `${params?.label} ${params?.language === 'en' ? 'should be a number' : 'يجب أن يكون رقماً'}`,
    date: (params) => `${params?.label} ${params?.language === 'en' ? 'should be a date' : 'يجب أن يكون تاريخاً'}`,
};

class LdcValidationMessagesComponent {
    constructor() {
        this.ERROR_MESSAGES = ERROR_MESSAGES;
        this.errors = {};
        this.defaultErrorMessage = "Invalid input";
        this._translate = inject(TranslateService);
    }
    getValidationErrorMessage() {
        return this.controller && this.controller.errors && this.controller.touched;
    }
    listOfErrors() {
        const lang = this._translate.currentLang || 'en';
        return Object.keys(this.controller.errors).map((err) => {
            return !err ? "Invalid" : this.errors && this.errors[err] ? this.errors[err] :
                this.ERROR_MESSAGES && this.ERROR_MESSAGES[err] ?
                    this.ERROR_MESSAGES[err]({
                        controllerErrors: this.controller.getError(err),
                        label: this.label,
                        language: lang
                    }) : this._translate.instant(this.defaultErrorMessage);
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LdcValidationMessagesComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: LdcValidationMessagesComponent, isStandalone: true, selector: "lib-ldc-validation-messages", inputs: { controller: "controller", errors: "errors", defaultErrorMessage: "defaultErrorMessage", label: "label" }, ngImport: i0, template: "<ng-container *ngIf=\"getValidationErrorMessage()\">\r\n    <mat-error *ngFor=\"let error of listOfErrors()\">\r\n      {{ error }}\r\n    </mat-error>\r\n  </ng-container>", styles: [".mat-mdc-form-field-error{font-size:.75rem}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i2.MatError, selector: "mat-error, [matError]", inputs: ["id"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LdcValidationMessagesComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lib-ldc-validation-messages', standalone: true, imports: [CommonModule, MatInputModule], template: "<ng-container *ngIf=\"getValidationErrorMessage()\">\r\n    <mat-error *ngFor=\"let error of listOfErrors()\">\r\n      {{ error }}\r\n    </mat-error>\r\n  </ng-container>", styles: [".mat-mdc-form-field-error{font-size:.75rem}\n"] }]
        }], propDecorators: { controller: [{
                type: Input,
                args: [{ required: true }]
            }], errors: [{
                type: Input
            }], defaultErrorMessage: [{
                type: Input
            }], label: [{
                type: Input,
                args: [{ required: true }]
            }] } });

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

export { ERROR_MESSAGES, LdcValidationMessagesComponent };
//# sourceMappingURL=testlocallibrary-shared-kernel-components-ldc-form-ldc-fields-ldc-validation-messages.mjs.map
