import { CommonModule } from '@angular/common';
import * as i1 from '@angular/common/http';
import { HttpEventType, HttpClientModule } from '@angular/common/http';
import * as i0 from '@angular/core';
import { Injectable, Component, Optional, Input, NgModule } from '@angular/core';
import * as i5 from '@angular/forms';
import { FormGroup, Validators, FormControl, FormArray, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormsModule, ReactiveFormsModule } from '@angular/forms';
import BigNumber from 'bignumber.js';
import { Subject, of, forkJoin, throwError } from 'rxjs';
import { takeUntil, finalize, catchError } from 'rxjs/operators';
import * as i6 from '@seniorsistemas/angular-components/dynamic-form';
import { DynamicType, FieldType, NumberFieldComponent, NumberField, FormField, DynamicFormModule } from '@seniorsistemas/angular-components/dynamic-form';
import moment from 'moment';
import * as i2 from '@seniorsistemas/angular-components/locale';
import { LocaleModule } from '@seniorsistemas/angular-components/locale';
import * as i3 from '@angular/platform-browser';
import * as i4 from '@ngx-translate/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';

var CustomFieldType;
(function (CustomFieldType) {
    CustomFieldType["String"] = "String";
    CustomFieldType["Boolean"] = "Boolean";
    CustomFieldType["Integer"] = "Integer";
    CustomFieldType["Double"] = "Double";
    CustomFieldType["Date"] = "Date";
    CustomFieldType["DateTime"] = "DateTime";
    CustomFieldType["LocalDateTime"] = "LocalDateTime";
    CustomFieldType["Time"] = "Time";
    CustomFieldType["Money"] = "Money";
    CustomFieldType["Blob"] = "Blob";
    CustomFieldType["Binary"] = "Binary";
    CustomFieldType["Any"] = "Any";
    CustomFieldType["Enum"] = "Enum";
})(CustomFieldType || (CustomFieldType = {}));

class CustomFieldsService {
    http;
    constructor(http) {
        this.http = http;
    }
    getCustomFields(domain, service, entity, endpoint) {
        const entityDto = { entityId: { domain_: domain, service_: service, id: entity } };
        return this.http.post(endpoint, entityDto);
    }
    getFileLocationUrl(dto, endpoint) {
        return this.http.post(endpoint, dto);
    }
    uploadTempFile(location, file) {
        return this.http.put(location, file, {
            reportProgress: true,
            observe: "events",
            headers: { "Content-Type": file.type }
        });
    }
    requestAccess(objectId, endpoint) {
        return this.http.post(endpoint, { objectId });
    }
    getFile(permanentUrl) {
        return this.http.get(permanentUrl, { responseType: "blob" });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsService, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.HttpClient }] });

class CustomFieldsComponent {
    customFieldsService;
    localeService;
    sanitizer;
    translateService;
    controlContainer;
    domain;
    service;
    entity;
    invalidErrorLabel = '';
    entityObject;
    customFieldsEndpoint = 'platform/field_customization/queries/getEntity';
    fileLocationEndpoint = 'platform/field_customization/actions/requestUpload';
    requestAccessEndpoint = 'platform/field_customization/actions/requestAccess';
    requiredErrorMessage = '';
    displayTimeInfoSign = 0;
    showFileUploadDate = false;
    ready$ = null;
    disableFields;
    rowType = DynamicType.Row;
    fields = [];
    formGroup = new FormGroup({});
    ready = false;
    onChange;
    onTouched;
    value;
    ngUsubscribe = new Subject();
    uploadCanceled;
    hasBlob;
    hasUploaded;
    constructor(customFieldsService, localeService, sanitizer, translateService, controlContainer) {
        this.customFieldsService = customFieldsService;
        this.localeService = localeService;
        this.sanitizer = sanitizer;
        this.translateService = translateService;
        this.controlContainer = controlContainer;
        this.invalidErrorLabel = this.translateService.instant('platform.angular_components.invalid_value');
    }
    get hasCustomFields() {
        return !!this.fields?.length;
    }
    get parentForm() {
        return this.controlContainer.control;
    }
    get parentControl() {
        return this.parentForm.get('custom');
    }
    ngOnInit() {
        this._validateInputs();
        this._createForm();
        this.addDisplayTimeInfoSignToFields();
    }
    ngAfterViewInit() {
        this.enableOrDisableFields(!!this.disableFields);
        this.formGroup.valueChanges.subscribe(() => this.onChange?.(this.parseFieldsValues()));
    }
    ngOnChanges(changes) {
        const _disableFields = changes['disableFields'];
        if (_disableFields) {
            this.enableOrDisableFields(_disableFields.currentValue);
        }
    }
    ngOnDestroy() {
        this.ngUsubscribe.next();
        this.ngUsubscribe.complete();
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    writeValue(value) {
        if (this.ready) {
            const newValue = this.parseValuesForFields(value);
            this.formGroup.patchValue(newValue);
            this.value = newValue;
            this.createFilesIfSetFormValuesAfterInit();
        }
        else {
            this.formGroup.patchValue(value || {});
            this.value = value;
        }
    }
    setDisabledState(isDisabled) {
        if (isDisabled) {
            this.formGroup.disable({ emitEvent: false });
        }
        else {
            this.formGroup.enable({ emitEvent: false });
        }
    }
    getCustomFields() {
        if (this.entityObject?.entity_) {
            return of(this.entityObject);
        }
        return this.customFieldsService.getCustomFields(this.domain, this.service, this.entity, this.customFieldsEndpoint);
    }
    validate() {
        const errors = {};
        Object.keys(this.formGroup.controls).forEach((field) => {
            const { errors: controlErrors } = this.formGroup.get(field);
            if (controlErrors) {
                errors[field] = controlErrors;
            }
        });
        return errors;
    }
    cleanFields() {
        this.formGroup.reset();
    }
    enableOrDisableFields(disabled) {
        if (!this.formGroup) {
            return;
        }
        for (const controlName of Object.keys(this.formGroup.value)) {
            disabled ? this.formGroup.get(controlName)?.disable() : this.formGroup.get(controlName)?.enable();
        }
    }
    _validateInputs() {
        if (!this.domain) {
            throw new Error('You need to specify the custom-fields domain!');
        }
        if (!this.service) {
            throw new Error('You need to specify the custom-fields service!');
        }
        if (!this.entity) {
            throw new Error('You need to specify the custom-fields entity!');
        }
    }
    _createForm() {
        this.formGroup = new FormGroup({});
        const observables = [this.getCustomFields(), this.localeService.get()];
        forkJoin(observables)
            .pipe(takeUntil(this.ngUsubscribe), finalize(() => {
            this.formGroup.markAsPristine();
            this.parentControl?.markAsPristine();
            if (this.ready$) {
                this.ready$.next(true);
            }
        }))
            .subscribe((response) => {
            const [customFieldsResponse, localeOptions] = response;
            const defaults = {};
            defaults[CustomFieldType.String] = {};
            defaults[CustomFieldType.Boolean] = { defaultValue: false };
            defaults[CustomFieldType.Integer] = {};
            defaults[CustomFieldType.Double] = { defaultMask: '' };
            defaults[CustomFieldType.Money] = {};
            defaults[CustomFieldType.Date] = {};
            defaults[CustomFieldType.DateTime] = {};
            defaults[CustomFieldType.LocalDateTime] = {};
            defaults[CustomFieldType.Time] = {};
            defaults[CustomFieldType.Blob] = {};
            defaults[CustomFieldType.Enum] = {};
            defaults[CustomFieldType.Binary] = {};
            defaults[CustomFieldType.Any] = {};
            if (!customFieldsResponse || !customFieldsResponse.entity_) {
                return;
            }
            const { active, fields } = customFieldsResponse.entity_;
            if (!active) {
                return;
            }
            fields
                .filter((field) => field.customizable && field.customization?.active)
                .forEach((field) => {
                const formField = this.getFormField(field, localeOptions);
                const fieldType = field.type;
                if (field.type === CustomFieldType.Blob && this.value && this.value[formField.name]) {
                    this.createBlobToFileUpload(formField);
                }
                const { validationRegex } = field.customization;
                const asIsTypes = [
                    CustomFieldType.Boolean,
                    CustomFieldType.Money,
                    CustomFieldType.Date,
                    CustomFieldType.DateTime,
                    CustomFieldType.LocalDateTime,
                    CustomFieldType.Time,
                ];
                const validators = [];
                if (validationRegex && !asIsTypes.includes(fieldType)) {
                    validators.push(Validators.pattern(validationRegex));
                }
                if (fieldType === CustomFieldType.Integer && !formField.mask) {
                    validators.push(Validators.pattern(/^\-?\d*$/));
                }
                if (formField.required?.()) {
                    validators.push(Validators.required);
                }
                const control = new FormControl({ value: defaults[fieldType].defaultValue, disabled: this.formGroup.disabled }, validators);
                this.formGroup.addControl(formField.name, control);
                this.fields.push(formField);
            });
            this.createFieldCustomization(fields);
            this.formGroup.patchValue(this.parseValuesForFields(this.value));
            this.ready = true;
        });
    }
    parseValuesForFields(values) {
        const parsedValues = { ...values };
        this.fields.forEach((field) => {
            const type = field.type;
            const name = field.name;
            const value = values?.[name];
            /**
             * Tratamento exclusivo para campos boolean que tem o status Empty
             * Essa condicional necessita estar antes do if (!value) return;
             * Pois ela tem um status que usa null no valor do campo radio boolean
             */
            if (type === FieldType.Boolean) {
                const isString = typeof value === 'string';
                const notValid = !isString && typeof value !== 'boolean';
                if (notValid) {
                    parsedValues[name] = null;
                }
                else {
                    // Condicional para campos que retornam string de boolen do backand
                    if (isString) {
                        parsedValues[name] = value === 'true' ? true : false;
                    }
                    else {
                        parsedValues[name] = value;
                    }
                }
            }
            if (!value) {
                return;
            }
            switch (type) {
                case FieldType.Date:
                    parsedValues[name] = moment(value).toDate();
                    break;
                case FieldType.DateTime:
                    parsedValues[name] = moment(value).toDate();
                    break;
                case FieldType.LocalDateTime:
                    parsedValues[name] = moment(value, 'YYYY-MM-DD[T]HH:mm:ss.SSS').toDate();
                    break;
                case FieldType.Time:
                    parsedValues[name] = moment(value, 'HH:mm:ss').toDate();
                    break;
                default:
                    break;
            }
        });
        return parsedValues;
    }
    /**
     * Algumas equipes só setam valor no formulário, após o carregamento da tela
     * Como é bem padrão isso, foi necessário criar esse método para gerar o file
     * após setar o valor no formulário
     */
    createFilesIfSetFormValuesAfterInit() {
        if (!this.hasUploaded) {
            this.fields
                .filter((field) => field.type === FieldType.Blob)
                .forEach((field) => {
                if (this.formGroup.get(field.name)?.value) {
                    this.createBlobToFileUpload(field);
                }
            });
        }
    }
    parseFieldsValues() {
        const parsedValues = {};
        this.fields.forEach((field) => {
            const { type, mask, scale } = field;
            const name = field.name;
            let value = this.formGroup.get(name)?.value;
            if (value) {
                switch (type) {
                    case FieldType.Number:
                        if (mask)
                            value = new BigNumber(value).toFixed(scale).toString();
                        break;
                    case FieldType.Date:
                        value = moment(value).format('YYYY-MM-DD');
                        break;
                    case FieldType.DateTime:
                        value = moment(value).format();
                        break;
                    case FieldType.LocalDateTime:
                        value = moment(value).format('YYYY-MM-DD[T]HH:mm:ss.SSS');
                        break;
                    case FieldType.Time:
                        value = moment(value).format('HH:mm:ss');
                        break;
                    default:
                        break;
                }
            }
            if ((value === null || value === undefined) && this.isTypeNumberOrEnum(type)) {
                parsedValues[name] = field.multiple ? [] : null;
            }
            else {
                parsedValues[name] = value;
            }
        });
        if (this.hasBlob) {
            parsedValues['fieldCustomization'] = this.formGroup.get('fieldCustomization')?.value;
        }
        return parsedValues;
    }
    isTypeNumberOrEnum(type) {
        const numberOrEnum = [FieldType.Number, FieldType.Enum];
        return numberOrEnum.includes(type);
    }
    getFormField(field, localeOptions) {
        let parameters = {};
        switch (field.type) {
            case CustomFieldType.Blob:
                parameters = this.getBlobParameters();
                break;
            case CustomFieldType.Boolean:
                parameters = this.getBooleanParameters();
                break;
            case 'Enumeration':
            case CustomFieldType.Enum:
                field.type = FieldType.Enum;
                parameters = this.getEnumParameters(field);
                break;
            case CustomFieldType.Money:
                parameters = {
                    type: FieldType.Custom,
                    CustomFieldComponentClass: NumberFieldComponent,
                    CustomFieldClass: NumberField,
                    precision: 15,
                    scale: 2,
                    leftAddon: {
                        label: localeOptions?.number?.currencySymbol ?? 'R$',
                    },
                    ignoreLabel: true,
                };
                break;
            case CustomFieldType.Double:
                parameters = {
                    type: FieldType.Custom,
                    CustomFieldComponentClass: NumberFieldComponent,
                    CustomFieldClass: NumberField,
                    precision: 15,
                    scale: 2,
                    ignoreLabel: true,
                };
                break;
            case CustomFieldType.Integer:
                parameters = {
                    type: FieldType.Custom,
                    CustomFieldComponentClass: NumberFieldComponent,
                    CustomFieldClass: NumberField,
                    precision: 15,
                    scale: 0,
                    ignoreLabel: true,
                };
                break;
            case CustomFieldType.Any:
                field.type = FieldType.String;
                break;
        }
        return new FormField({
            name: field.id,
            label: field.customization.label,
            tooltip: field.customization.tooltip,
            infoSign: field.customization.infoSign,
            type: field.type,
            mask: field.customization.mask,
            required: () => field.customization.mandatory,
            calendarOptions: localeOptions.calendar,
            currencyOptions: localeOptions.number,
            ...parameters,
        });
    }
    getEnumParameters(field) {
        return {
            showClear: true,
            multiple: field.customization.customEnumeration.multiple,
            options: field.customization.customEnumeration.values.map((e) => ({ label: e.value, value: e.key })),
        };
    }
    getBooleanParameters() {
        return {
            optionsLabel: {
                true: this.getTranslateLabel(`true_label`),
                false: this.getTranslateLabel(`false_label`),
                empty: this.getTranslateLabel(`empty_label`),
            },
        };
    }
    getBlobParameters() {
        return {
            size: {
                sm: 12,
                md: 12,
                lg: 12,
                xl: 12,
            },
            accept: 'image/*, application/*, text/*',
            chooseLabel: this.getTranslateLabel(`choose_label`),
            removeLabel: this.getTranslateLabel(`remove_label`),
            cancelLabel: this.getTranslateLabel(`cancel_label`),
            successTooltip: this.getTranslateLabel(`success_tooltip`),
            multiple: false,
            onUploadFile: (event, formfield) => {
                this.hasUploaded = true;
                this.uploadFile(event, formfield);
            },
            onRemoveFile: (event, formfield) => {
                this.removeFile(event, formfield);
            },
            onCancelUpload: (event, formfield) => {
                this.cancelUpload(event, formfield);
            },
            onDownloadFile: (event, formfield) => {
                this.downloadFile(event, formfield);
            },
            showFileUploadDate: this.showFileUploadDate,
        };
    }
    /**
     * É necessário criar o fieldCustomization quando há um Blob na entidade para gerar o
     * com os fields inseridos e deletados.
     */
    createFieldCustomization(fields) {
        this.hasBlob = !!fields.filter((field) => field.type === CustomFieldType.Blob).length;
        if (this.hasBlob) {
            this.formGroup.addControl('fieldCustomization', new FormArray([
                new FormGroup({
                    domain: new FormControl(this.domain),
                    service: new FormControl(this.service),
                    entity: new FormControl(this.entity),
                    toDelete: new FormControl({ value: {}, disabled: false }),
                    toInsert: new FormControl({ value: {}, disabled: false }),
                }),
            ]));
        }
    }
    createBlobToFileUpload(field) {
        const _name = field.name;
        const objectId = this.value[_name] ? this.value[_name] : this.formGroup.get(_name)?.value;
        const fileName = objectId.substring(objectId.lastIndexOf('/') + 1);
        const file = { objectId, name: fileName, savedFile: true };
        field.files = [file];
    }
    downloadFile(event, field) {
        const { index, anchor } = event;
        const _files = field.files || [];
        if (!_files.length) {
            return;
        }
        const currentFile = _files[index];
        if (currentFile.objectURL) {
            anchor.nativeElement.click();
        }
        else {
            const _objectId = currentFile.objectId;
            this.customFieldsService
                .requestAccess(_objectId, this.requestAccessEndpoint)
                .pipe(takeUntil(this.ngUsubscribe))
                .subscribe((data) => {
                const { fileName, uri } = data;
                this.customFieldsService
                    .getFile(uri)
                    .pipe(takeUntil(this.ngUsubscribe))
                    .subscribe((blob) => {
                    const newFile = new File([blob], fileName);
                    newFile.objectURL = this.sanitizer.bypassSecurityTrustUrl(uri);
                    anchor.nativeElement.setAttribute('href', uri);
                    newFile.objectId = currentFile.objectId;
                    newFile.savedFile = true;
                    _files[index] = newFile;
                    field.files = [..._files];
                    anchor.nativeElement.click();
                });
            });
        }
    }
    uploadFile(event, formField) {
        const { files } = event;
        const field = this.fields.find((record) => record.name === formField.name);
        if (!field) {
            return;
        }
        // Se ocorrer um upload, já existindo um arquivo com upload feito. É necessário excluir o mesmo.
        if (field?.files?.length) {
            this.removeFile({ file: field.files[0] }, field);
        }
        field.files = files;
        const _name = field.name;
        for (let i = 0; i < files.length; i++) {
            const file = files[i];
            if (!file.savedFile && !file.progress) {
                file.isUploading = true;
                this.formGroup.get(_name)?.setValidators(isUploading(file));
                this.formGroup.get(_name)?.updateValueAndValidity();
                this.customFieldsService
                    .getFileLocationUrl({
                    domain: this.domain,
                    service: this.service,
                    entityName: this.entity,
                    field: _name,
                    fileName: file.name,
                }, this.fileLocationEndpoint)
                    .pipe(takeUntil(this.ngUsubscribe), catchError((err) => of(this.defaltCatchError(field, err, i))))
                    .subscribe((data) => {
                    const { location, version, objectId } = data;
                    file.version = version;
                    file.objectId = objectId;
                    file.uploadSubscribe = this.customFieldsService
                        .uploadTempFile(location, file)
                        .pipe(takeUntil(this.ngUsubscribe), catchError((err) => of(this.defaltCatchError(field, err, i))), finalize(() => {
                        file.isUploading = false;
                    }))
                        .subscribe((response) => {
                        const { type } = response;
                        if (!this.uploadCanceled) {
                            if (type === HttpEventType.UploadProgress) {
                                file.progress = Math.round(response.loaded / response.total) * 100;
                            }
                            else if (type === HttpEventType.Response) {
                                file.objectURL = this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(file));
                                const value = { objectId, name: file.name, version: file.version };
                                const toInsert = this.formGroup.get('fieldCustomization')?.value[0].toInsert;
                                const fieldCustomization = this.formGroup.get('fieldCustomization')?.value;
                                if (fieldCustomization?.value?.[0]) {
                                    fieldCustomization.value[0].toInsert = {
                                        ...toInsert,
                                        [_name]: value,
                                    };
                                }
                                this.formGroup.get(_name)?.setValue(`${file.objectId}/${file.name}`);
                                this.formGroup.get(_name)?.clearValidators();
                                this.formGroup.get(_name)?.updateValueAndValidity();
                                field.files = [file];
                            }
                        }
                        else if (this.uploadCanceled && type === HttpEventType.Response) {
                            this.uploadCanceled = false;
                        }
                    });
                    field.files = [file];
                });
            }
        }
    }
    removeFile(event, formField) {
        const { file } = event;
        const field = this.fields.find((record) => record.name === formField.name);
        field.files = [];
        if (file.objectId) {
            // Quando é um arquivo já salvo o objectId já é no formato "objectId/name"
            const value = file.savedFile ? `${file.objectId}` : `${file.objectId}/${file.name}`;
            const toDelete = this.formGroup.get("fieldCustomization").value[0].toDelete;
            delete this.formGroup.get("fieldCustomization").value[0].toInsert[field.name];
            this.formGroup.get("fieldCustomization").value[0].toDelete = {
                ...toDelete,
                [field.name]: [...(toDelete[field.name] || []), value],
            };
        }
        this.formGroup.get(field.name).clearValidators();
        this.formGroup.get(field.name).setValue("");
        this.formGroup.get(field.name).updateValueAndValidity();
    }
    cancelUpload(index, formField) {
        this.uploadCanceled = true;
        const field = this.fields.find((record) => record.name === formField.name);
        if (!field) {
            return;
        }
        const _name = field.name;
        const _files = field.files || [];
        _files[index]?.uploadSubscribe?.unsubscribe();
        field.files = [];
        const fieldCustomization = this.formGroup.get('fieldCustomization')?.value[0];
        delete fieldCustomization.toInsert[_name];
        this.formGroup.get(_name)?.clearValidators();
        this.formGroup.get(_name)?.setValue('');
        this.formGroup.get(_name)?.updateValueAndValidity();
    }
    defaltCatchError(field, err, index) {
        const { files } = field;
        if (files) {
            files[index].error = err;
            files[index].isUploading = false;
            field.files = [...files];
            const _name = field.name;
            this.formGroup.get(_name)?.setValidators([errorOnUpload(files[index])]);
            this.formGroup.get(_name)?.updateValueAndValidity();
            return throwError(() => new Error('error in upload file. Details: ' + err.message));
        }
        else {
            return throwError(() => new Error('error in upload file. Details: ' + err.message));
        }
    }
    getTranslateLabel(label) {
        return this.translateService.instant(`${this.domain}.${this.service}.${label}`);
    }
    addDisplayTimeInfoSignToFields() {
        this.fields.forEach((field) => {
            field.displayTimeInfoSign = this.displayTimeInfoSign;
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsComponent, deps: [{ token: CustomFieldsService }, { token: i2.LocaleService }, { token: i3.DomSanitizer }, { token: i4.TranslateService }, { token: i5.ControlContainer, optional: true }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: CustomFieldsComponent, selector: "s-custom-fields", inputs: { domain: "domain", service: "service", entity: "entity", invalidErrorLabel: "invalidErrorLabel", entityObject: "entityObject", customFieldsEndpoint: "customFieldsEndpoint", fileLocationEndpoint: "fileLocationEndpoint", requestAccessEndpoint: "requestAccessEndpoint", requiredErrorMessage: "requiredErrorMessage", displayTimeInfoSign: "displayTimeInfoSign", showFileUploadDate: "showFileUploadDate", ready$: "ready$", disableFields: "disableFields" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: CustomFieldsComponent,
                multi: true,
            },
            {
                provide: NG_VALIDATORS,
                useExisting: CustomFieldsComponent,
                multi: true,
            },
        ], usesOnChanges: true, ngImport: i0, template: "@let errorMessages = {\n    pattern: invalidErrorLabel,\n    required: requiredErrorMessage\n};\n\n@let configs = [\n    {\n        type: rowType,\n        fields\n    }\n];\n\n<s-dynamic-form\n    [configs]=\"configs\"\n    [form]=\"formGroup\"\n    [errorMessages]=\"errorMessages\">\n</s-dynamic-form>\n", dependencies: [{ kind: "component", type: i6.DynamicFormComponent, selector: "s-dynamic-form", inputs: ["id", "configs", "fields", "form", "errorMessages"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-custom-fields', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: CustomFieldsComponent,
                            multi: true,
                        },
                        {
                            provide: NG_VALIDATORS,
                            useExisting: CustomFieldsComponent,
                            multi: true,
                        },
                    ], template: "@let errorMessages = {\n    pattern: invalidErrorLabel,\n    required: requiredErrorMessage\n};\n\n@let configs = [\n    {\n        type: rowType,\n        fields\n    }\n];\n\n<s-dynamic-form\n    [configs]=\"configs\"\n    [form]=\"formGroup\"\n    [errorMessages]=\"errorMessages\">\n</s-dynamic-form>\n" }]
        }], ctorParameters: () => [{ type: CustomFieldsService }, { type: i2.LocaleService }, { type: i3.DomSanitizer }, { type: i4.TranslateService }, { type: i5.ControlContainer, decorators: [{
                    type: Optional
                }] }], propDecorators: { domain: [{
                type: Input,
                args: [{ required: true }]
            }], service: [{
                type: Input,
                args: [{ required: true }]
            }], entity: [{
                type: Input,
                args: [{ required: true }]
            }], invalidErrorLabel: [{
                type: Input
            }], entityObject: [{
                type: Input
            }], customFieldsEndpoint: [{
                type: Input
            }], fileLocationEndpoint: [{
                type: Input
            }], requestAccessEndpoint: [{
                type: Input
            }], requiredErrorMessage: [{
                type: Input
            }], displayTimeInfoSign: [{
                type: Input
            }], showFileUploadDate: [{
                type: Input
            }], ready$: [{
                type: Input
            }], disableFields: [{
                type: Input
            }] } });
function isUploading(file) {
    return () => (file.isUploading ? { isUploading: true } : null);
}
function errorOnUpload(file) {
    return () => (file.error ? { uploadError: true } : null);
}

class CustomFieldsModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsModule, declarations: [CustomFieldsComponent], imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            HttpClientModule,
            LocaleModule,
            DynamicFormModule,
            TranslateModule], exports: [CustomFieldsComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsModule, providers: [CustomFieldsService, TranslateService], imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            HttpClientModule,
            LocaleModule,
            DynamicFormModule,
            TranslateModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CustomFieldsModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        HttpClientModule,
                        LocaleModule,
                        DynamicFormModule,
                        TranslateModule
                    ],
                    declarations: [CustomFieldsComponent],
                    exports: [CustomFieldsComponent],
                    providers: [CustomFieldsService, TranslateService]
                }]
        }] });

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

export { CustomFieldsComponent, CustomFieldsModule, CustomFieldsService };
//# sourceMappingURL=seniorsistemas-angular-components-custom-fields.mjs.map
