import * as i0 from '@angular/core';
import { EventEmitter, Component, Output, Input, ContentChild } from '@angular/core';
import * as i1 from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';
import { NgIf, NgForOf, NgClass } from '@angular/common';
import { ReplaySubject } from 'rxjs';
import { LdcFieldBuilderComponent } from '@testlocallibrary/shared-kernel/components/ldc-form/ldc-dynamic-form/ldc-field-builder';
import { LdcFormArrayBuilderComponent } from '@testlocallibrary/shared-kernel/components/ldc-form/ldc-dynamic-form/ldc-form-array-builder';
import { LdcDynamicButtonsComponent } from '@testlocallibrary/shared-kernel/components/ldc-dynamic-buttons';
import * as i2 from '@ngx-translate/core';
import { TranslateModule } from '@ngx-translate/core';

class LdcDynamicFormsComponent {
    constructor(_fb) {
        this._fb = _fb;
        this.onSubmit = new EventEmitter();
        this.onClose = new EventEmitter();
        this.fields = [];
        this.errors = {};
        this.alignButtons = 'end';
        this.isStickyForm = false;
        this._destroyAll$ = new ReplaySubject(1);
    }
    ngOnInit() {
        this.initializeForm();
    }
    ngOnChanges(changes) {
        if (changes['fields'].currentValue != changes['fields'].previousValue) {
            this.initializeForm();
        }
    }
    submit() {
        if (this.form.invalid)
            return this.form.markAllAsTouched();
        this.onSubmit.emit({ formData: this.form.value, form: this.form });
    }
    ngOnDestroy() {
        this._destroyAll$.next(true);
        this._destroyAll$.complete();
    }
    initializeForm() {
        let formControllers = {};
        for (const field of this.fields) {
            if (field?.controller?.controllerArray)
                formControllers[field.controller.name] = field.controller
                    .controllerArray;
            else
                formControllers[field.controller.name] = field.controller
                    .controller;
        }
        this.form = this._fb.group(formControllers);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LdcDynamicFormsComponent, deps: [{ token: i1.FormBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: LdcDynamicFormsComponent, isStandalone: true, selector: "lib-ldc-dynamic-form", inputs: { buttons: "buttons", fields: "fields", errors: "errors", alignButtons: "alignButtons", isStickyForm: "isStickyForm" }, outputs: { onSubmit: "onSubmit", onClose: "onClose" }, queries: [{ propertyName: "content", first: true, predicate: ["content"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<ng-container *ngIf=\"form\">\r\n  <form\r\n    (ngSubmit)=\"submit()\"\r\n    [formGroup]=\"form\"\r\n    [ngClass]=\"{ 'sticky-form': isStickyForm }\"\r\n    class=\"row\"\r\n  >\r\n    <ng-container *ngFor=\"let field of fields\">\r\n      <h4 *ngIf=\"field?.previousHeadLine\"\r\n          class=\"{{ field?.containerStyle }} col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 pb-4 mb-3\">\r\n        {{ (field?.previousHeadLine ?? '') | translate }}\r\n      </h4>\r\n      <div class=\"col-{{ field?.columnSize }} {{ field?.containerStyle }}\">\r\n        <ng-container\r\n          *ngIf=\"!field?.controller?.controllerArray; else formArrayTemplate\"\r\n        >\r\n          <lib-ldc-field-builder\r\n            [errors]=\"errors\"\r\n            [inputSpecification]=\"field\"\r\n          />\r\n        </ng-container>\r\n        <ng-template #formArrayTemplate>\r\n          <lib-ldc-form-array-builder\r\n            [arrayController]=\"field.controller.name\"\r\n            [fields]=\"field.controllerSpecification.group ?? []\"\r\n            [formGroup]=\"form\"\r\n            [label]=\"field.placeholder\"\r\n          ></lib-ldc-form-array-builder>\r\n        </ng-template>\r\n      </div>\r\n      <h4 *ngIf=\"field?.nextHeadLine\"\r\n          class=\"{{ field?.containerStyle }} col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12\">\r\n        {{ (field?.nextHeadLine ?? '') | translate }}\r\n      </h4>\r\n    </ng-container>\r\n    <ng-content select=\"[content]\"></ng-content>\r\n    <div\r\n      class=\"text-{{ alignButtons }} my-2\"\r\n      [ngClass]=\"{ ' sticky-btn': isStickyForm }\"\r\n    >\r\n      <lib-ldc-dynamic-buttons [buttons]=\"buttons\"/>\r\n    </div>\r\n   \r\n  </form>\r\n</ng-container>\r\n", styles: [".sticky-btn{padding:16px;position:absolute;right:16px;bottom:0;width:100%}.sticky-form{height:40vh;overflow-y:scroll;padding:0 16px}::ng-deep .mat-mdc-form-field-subscript-wrapper{display:none}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "component", type: LdcFieldBuilderComponent, selector: "lib-ldc-field-builder", inputs: ["inputSpecification", "errors"] }, { kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: LdcDynamicButtonsComponent, selector: "lib-ldc-dynamic-buttons", inputs: ["buttons", "item"] }, { kind: "component", type: LdcFormArrayBuilderComponent, selector: "lib-ldc-form-array-builder", inputs: ["arrayController", "formGroup", "label", "fields"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i2.TranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LdcDynamicFormsComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lib-ldc-dynamic-form', imports: [
                        NgIf,
                        ReactiveFormsModule,
                        LdcFieldBuilderComponent,
                        NgForOf,
                        LdcDynamicButtonsComponent,
                        LdcFormArrayBuilderComponent,
                        NgClass,
                        TranslateModule,
                    ], standalone: true, template: "<ng-container *ngIf=\"form\">\r\n  <form\r\n    (ngSubmit)=\"submit()\"\r\n    [formGroup]=\"form\"\r\n    [ngClass]=\"{ 'sticky-form': isStickyForm }\"\r\n    class=\"row\"\r\n  >\r\n    <ng-container *ngFor=\"let field of fields\">\r\n      <h4 *ngIf=\"field?.previousHeadLine\"\r\n          class=\"{{ field?.containerStyle }} col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 pb-4 mb-3\">\r\n        {{ (field?.previousHeadLine ?? '') | translate }}\r\n      </h4>\r\n      <div class=\"col-{{ field?.columnSize }} {{ field?.containerStyle }}\">\r\n        <ng-container\r\n          *ngIf=\"!field?.controller?.controllerArray; else formArrayTemplate\"\r\n        >\r\n          <lib-ldc-field-builder\r\n            [errors]=\"errors\"\r\n            [inputSpecification]=\"field\"\r\n          />\r\n        </ng-container>\r\n        <ng-template #formArrayTemplate>\r\n          <lib-ldc-form-array-builder\r\n            [arrayController]=\"field.controller.name\"\r\n            [fields]=\"field.controllerSpecification.group ?? []\"\r\n            [formGroup]=\"form\"\r\n            [label]=\"field.placeholder\"\r\n          ></lib-ldc-form-array-builder>\r\n        </ng-template>\r\n      </div>\r\n      <h4 *ngIf=\"field?.nextHeadLine\"\r\n          class=\"{{ field?.containerStyle }} col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12\">\r\n        {{ (field?.nextHeadLine ?? '') | translate }}\r\n      </h4>\r\n    </ng-container>\r\n    <ng-content select=\"[content]\"></ng-content>\r\n    <div\r\n      class=\"text-{{ alignButtons }} my-2\"\r\n      [ngClass]=\"{ ' sticky-btn': isStickyForm }\"\r\n    >\r\n      <lib-ldc-dynamic-buttons [buttons]=\"buttons\"/>\r\n    </div>\r\n   \r\n  </form>\r\n</ng-container>\r\n", styles: [".sticky-btn{padding:16px;position:absolute;right:16px;bottom:0;width:100%}.sticky-form{height:40vh;overflow-y:scroll;padding:0 16px}::ng-deep .mat-mdc-form-field-subscript-wrapper{display:none}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.FormBuilder }]; }, propDecorators: { onSubmit: [{
                type: Output
            }], onClose: [{
                type: Output
            }], buttons: [{
                type: Input
            }], fields: [{
                type: Input,
                args: [{ required: true }]
            }], errors: [{
                type: Input
            }], alignButtons: [{
                type: Input
            }], isStickyForm: [{
                type: Input
            }], content: [{
                type: ContentChild,
                args: ['content']
            }] } });

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

export { LdcDynamicFormsComponent };
//# sourceMappingURL=testlocallibrary-shared-kernel-components-ldc-form-ldc-dynamic-form-ldc-dynamic-form.mjs.map
