import { Component, inject, input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { NgClass } from '@angular/common';
import { ButtonComponent } from '@seniorsistemas/angular-components/button';
import { ControlErrorsModule } from '@seniorsistemas/angular-components/control-errors';
import { STRUCTURE_TYPES_LIST } from '../../../configurations/structure/structure';
import { DynamicFormDirective } from '../../../dynamic-form.directive';
import { FieldSize } from '../../../form-field/configurations/field-size';
import { FormFieldUtilsService } from '../../../services/form-field-utils.service';
import * as i0 from "@angular/core";
import * as i1 from "@seniorsistemas/angular-components/control-errors";
import * as i2 from "@angular/forms";
export class RowComponent {
    id = input();
    config = input.required();
    group = input.required();
    errorMessages = input();
    formUtils = inject(FormFieldUtilsService);
    getErrorMessages(errorMessages) {
        if (errorMessages)
            return this.isFunction(errorMessages) ? errorMessages() : errorMessages;
        return this.errorMessages();
    }
    isFunction(value) {
        return value instanceof Function;
    }
    fieldIsExpandedDynamicType(field) {
        return !STRUCTURE_TYPES_LIST.includes(field.type);
    }
    fieldGridClass(field) {
        const fieldSize = new FieldSize(field.size ?? {});
        return fieldSize.getGridClass();
    }
    getName(field) {
        if ('customName' in field && field.customName) {
            return field.customName;
        }
        else if ('name' in field) {
            return field.name;
        }
        return '';
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: RowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: RowComponent, isStandalone: true, selector: "s-row", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, group: { classPropertyName: "group", publicName: "group", isSignal: true, isRequired: true, transformFunction: null }, errorMessages: { classPropertyName: "errorMessages", publicName: "errorMessages", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<div\n    class=\"w-full\"\n    [formGroup]=\"group()\"\n>\n    @let rowConfig = config();\n    @let rowIsVisible = formUtils.getFieldProperty(rowConfig.visible, true);\n    @if (rowIsVisible) {\n        <div class=\"grid w-screen max-w-full grid-cols-12 gap-4\">\n            @for (field of config().fields; let i = $index; track i) {\n                @let fieldName = getName(field);\n                @if (fieldIsExpandedDynamicType(field)) {\n                    @let fieldVisible = formUtils.getFieldProperty(field.visible, true);\n                    @if (fieldVisible) {\n                        <div\n                            class=\"p-1\"\n                            [ngClass]=\"fieldGridClass(field)\"\n                        >\n                            <ng-container *sDynamicForm=\"{ id: id(), config: field, group: group() }\"></ng-container>\n\n                            @if (fieldName) {\n                                <s-control-errors\n                                    [form]=\"group\"\n                                    [control]=\"group().controls[fieldName]\"\n                                    [errorMessages]=\"getErrorMessages(field.errorMessages)\"\n                                ></s-control-errors>\n                            }\n\n                            @if (field.footer) {\n                                @if (field.footer.help) {\n                                    @let footerHelpVisible =\n                                        field.footer.help.visible?.({\n                                            abstractControl: group().controls[fieldName],\n                                            formField: field,\n                                        });\n                                    @if (fieldName && field.footer.help.visible ? footerHelpVisible : true) {\n                                        <span style=\"color: #888b99\">\n                                            {{ field.footer.help.text }}\n                                        </span>\n                                    }\n                                }\n                            }\n\n                            @if (field.footer) {\n                                @let footerLinkVisible =\n                                    field.footer.link?.visible?.({\n                                        abstractControl: group().controls[fieldName],\n                                        formField: field,\n                                    });\n                                @if (fieldName && field.footer.link?.visible ? footerLinkVisible : true) {\n                                    <div style=\"margin-left: -17px\">\n                                        <s-button\n                                            [label]=\"field.footer.link?.label\"\n                                            priority=\"link\"\n                                            (clicked)=\"\n                                                field.footer.link?.onClick({\n                                                    abstractControl: group().controls[fieldName],\n                                                    formField: field,\n                                                })\n                                            \"\n                                            [auxiliary]=\"true\"\n                                        ></s-button>\n                                    </div>\n                                }\n                            }\n                            @if (field.bottomTemplate) {\n                                <ng-template [ngTemplateOutlet]=\"field.bottomTemplate\"></ng-template>\n                            }\n                        </div>\n                    }\n                } @else {\n                    @let gridClass = fieldGridClass(field);\n                    <div [ngClass]=\"gridClass\">\n                        <ng-container *sDynamicForm=\"{ id: id(), config: field, group: group() }\"></ng-container>\n                    </div>\n                }\n            }\n        </div>\n    }\n</div>\n\n", dependencies: [{ kind: "ngmodule", type: ControlErrorsModule }, { kind: "component", type: i1.ControlErrorsComponent, selector: "s-control-errors", inputs: ["id", "control", "errorMessages", "form"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: ButtonComponent, selector: "s-button", inputs: ["id", "label", "tooltip", "tooltipPosition", "iconClass", "rightIconClass", "caret", "styleClass", "baseZIndex", "disabled", "auxiliary", "type", "priority", "menuOptions", "size", "slide", "animation", "badge", "iconColor", "menuAriaLabel"], outputs: ["clicked"] }, { kind: "directive", type: DynamicFormDirective, selector: "[sDynamicForm]", inputs: ["sDynamicForm"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: RowComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-row', standalone: true, imports: [ControlErrorsModule, ReactiveFormsModule, NgClass, ButtonComponent, DynamicFormDirective], template: "<div\n    class=\"w-full\"\n    [formGroup]=\"group()\"\n>\n    @let rowConfig = config();\n    @let rowIsVisible = formUtils.getFieldProperty(rowConfig.visible, true);\n    @if (rowIsVisible) {\n        <div class=\"grid w-screen max-w-full grid-cols-12 gap-4\">\n            @for (field of config().fields; let i = $index; track i) {\n                @let fieldName = getName(field);\n                @if (fieldIsExpandedDynamicType(field)) {\n                    @let fieldVisible = formUtils.getFieldProperty(field.visible, true);\n                    @if (fieldVisible) {\n                        <div\n                            class=\"p-1\"\n                            [ngClass]=\"fieldGridClass(field)\"\n                        >\n                            <ng-container *sDynamicForm=\"{ id: id(), config: field, group: group() }\"></ng-container>\n\n                            @if (fieldName) {\n                                <s-control-errors\n                                    [form]=\"group\"\n                                    [control]=\"group().controls[fieldName]\"\n                                    [errorMessages]=\"getErrorMessages(field.errorMessages)\"\n                                ></s-control-errors>\n                            }\n\n                            @if (field.footer) {\n                                @if (field.footer.help) {\n                                    @let footerHelpVisible =\n                                        field.footer.help.visible?.({\n                                            abstractControl: group().controls[fieldName],\n                                            formField: field,\n                                        });\n                                    @if (fieldName && field.footer.help.visible ? footerHelpVisible : true) {\n                                        <span style=\"color: #888b99\">\n                                            {{ field.footer.help.text }}\n                                        </span>\n                                    }\n                                }\n                            }\n\n                            @if (field.footer) {\n                                @let footerLinkVisible =\n                                    field.footer.link?.visible?.({\n                                        abstractControl: group().controls[fieldName],\n                                        formField: field,\n                                    });\n                                @if (fieldName && field.footer.link?.visible ? footerLinkVisible : true) {\n                                    <div style=\"margin-left: -17px\">\n                                        <s-button\n                                            [label]=\"field.footer.link?.label\"\n                                            priority=\"link\"\n                                            (clicked)=\"\n                                                field.footer.link?.onClick({\n                                                    abstractControl: group().controls[fieldName],\n                                                    formField: field,\n                                                })\n                                            \"\n                                            [auxiliary]=\"true\"\n                                        ></s-button>\n                                    </div>\n                                }\n                            }\n                            @if (field.bottomTemplate) {\n                                <ng-template [ngTemplateOutlet]=\"field.bottomTemplate\"></ng-template>\n                            }\n                        </div>\n                    }\n                } @else {\n                    @let gridClass = fieldGridClass(field);\n                    <div [ngClass]=\"gridClass\">\n                        <ng-container *sDynamicForm=\"{ id: id(), config: field, group: group() }\"></ng-container>\n                    </div>\n                }\n            }\n        </div>\n    }\n</div>\n\n" }]
        }] });
//# sourceMappingURL=data:application/json;base64, 