import { Component, Input } from '@angular/core';
import { tap } from 'rxjs/operators';
import * as i0 from "@angular/core";
import * as i1 from "../../services/smz-forms-dropdown.service";
import * as i2 from "@angular/common";
import * as i3 from "primeng/dropdown";
import * as i4 from "@angular/flex-layout/flex";
import * as i5 from "@angular/flex-layout/extended";
import * as i6 from "@angular/forms";
import * as i7 from "../validation-messages/validation-messages.component";
export class LinkedDropdownComponent {
    constructor(service) {
        this.service = service;
    }
    ngOnInit() {
        this.service.registryDependsOnData(this.input, this.formId);
        this.service.registryObserver(this.input, this.formId);
    }
    ngAfterViewInit() {
        this.options$ = this.service.observers[this.formId + this.input.propertyName]?.options
            .pipe(tap(options => {
            if (options?.length > 0 && this.input.defaultValue != null) {
                if (this.input.defaultValue.id != null) {
                    // Default value encontrado no formato SimpleEntity
                    setTimeout(() => {
                        this.control.patchValue(options.find(x => x.id === this.input.defaultValue.id));
                    }, 0);
                }
                else {
                    // Default value encontrado no formato string
                    const value = options.find(x => x.id === this.input.defaultValue);
                    setTimeout(() => {
                        this.control.patchValue(value ?? '');
                    }, 0);
                }
            }
        }));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: LinkedDropdownComponent, deps: [{ token: i1.SmzFormsDropdownService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.5", type: LinkedDropdownComponent, selector: "smz-linked-dropdown", inputs: { input: "input", formId: "formId", control: "control", behaviors: "behaviors" }, ngImport: i0, template: "<ng-container *ngIf=\"options$ | async as options\">\r\n\r\n<div class=\"ui-g ui-fluid\">\r\n    <div class=\"ui-g-12 grid-nogutter\" [ngStyle]=\"{ padding: 0 }\">\r\n        <label *ngIf=\"input.hideLabel != true\" class=\"smz__input_name\" [innerHTML]=\"input.name\"></label>\r\n        <div class=\"input_inner__wrapper grid grid-nogutter\">\r\n            <p-dropdown\r\n                fxFlex=\"grow\"\r\n                class=\"col-12 grid-nogutter smz__input_value\"\r\n                [options]=\"options\"\r\n                [formControl]=\"control\"\r\n                optionLabel=\"name\"\r\n                [autoDisplayFirst]=\"false\"\r\n                dataKey=\"id\"\r\n                appendTo=\"body\"\r\n                (onChange)=\"service.setValue(input, formId, $event)\"\r\n                [filter]=\"input.showFilter ? true : false\"\r\n                [filterMatchMode]=\"input.filterMatchMode != null ? input.filterMatchMode : 'contains'\"\r\n                [showClear]=\"input.showClear\"\r\n                [emptyMessage]=\"input.emptyMessage\"\r\n                [emptyFilterMessage]=\"input.emptyFilterMessage\"\r\n                [autofocusFilter]=\"input.autofocusFilter\">\r\n            </p-dropdown>\r\n            <smz-validation-messages [input]=\"input\" [control]=\"control\" [behaviors]=\"behaviors\"></smz-validation-messages>\r\n        </div>\r\n    </div>\r\n</div>\r\n\r\n</ng-container>", dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: i3.Dropdown, selector: "p-dropdown", inputs: ["id", "scrollHeight", "filter", "name", "style", "panelStyle", "styleClass", "panelStyleClass", "readonly", "required", "editable", "appendTo", "tabindex", "placeholder", "filterPlaceholder", "filterLocale", "inputId", "dataKey", "filterBy", "filterFields", "autofocus", "resetFilterOnHide", "dropdownIcon", "optionLabel", "optionValue", "optionDisabled", "optionGroupLabel", "optionGroupChildren", "autoDisplayFirst", "group", "showClear", "emptyFilterMessage", "emptyMessage", "lazy", "virtualScroll", "virtualScrollItemSize", "virtualScrollOptions", "overlayOptions", "ariaFilterLabel", "ariaLabel", "ariaLabelledBy", "filterMatchMode", "maxlength", "tooltip", "tooltipPosition", "tooltipPositionStyle", "tooltipStyleClass", "focusOnHover", "selectOnFocus", "autoOptionFocus", "autofocusFilter", "disabled", "itemSize", "autoZIndex", "baseZIndex", "showTransitionOptions", "hideTransitionOptions", "filterValue", "options"], outputs: ["onChange", "onFilter", "onFocus", "onBlur", "onClick", "onShow", "onHide", "onClear", "onLazyLoad"] }, { kind: "directive", type: i4.DefaultFlexDirective, selector: "  [fxFlex], [fxFlex.xs], [fxFlex.sm], [fxFlex.md],  [fxFlex.lg], [fxFlex.xl], [fxFlex.lt-sm], [fxFlex.lt-md],  [fxFlex.lt-lg], [fxFlex.lt-xl], [fxFlex.gt-xs], [fxFlex.gt-sm],  [fxFlex.gt-md], [fxFlex.gt-lg]", inputs: ["fxFlex", "fxFlex.xs", "fxFlex.sm", "fxFlex.md", "fxFlex.lg", "fxFlex.xl", "fxFlex.lt-sm", "fxFlex.lt-md", "fxFlex.lt-lg", "fxFlex.lt-xl", "fxFlex.gt-xs", "fxFlex.gt-sm", "fxFlex.gt-md", "fxFlex.gt-lg"] }, { kind: "directive", type: i5.DefaultStyleDirective, selector: "  [ngStyle],  [ngStyle.xs], [ngStyle.sm], [ngStyle.md], [ngStyle.lg], [ngStyle.xl],  [ngStyle.lt-sm], [ngStyle.lt-md], [ngStyle.lt-lg], [ngStyle.lt-xl],  [ngStyle.gt-xs], [ngStyle.gt-sm], [ngStyle.gt-md], [ngStyle.gt-lg]", inputs: ["ngStyle", "ngStyle.xs", "ngStyle.sm", "ngStyle.md", "ngStyle.lg", "ngStyle.xl", "ngStyle.lt-sm", "ngStyle.lt-md", "ngStyle.lt-lg", "ngStyle.lt-xl", "ngStyle.gt-xs", "ngStyle.gt-sm", "ngStyle.gt-md", "ngStyle.gt-lg"] }, { kind: "directive", type: i6.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i6.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i7.ValidationMessagesComponent, selector: "smz-validation-messages", inputs: ["input", "control", "behaviors", "extraMessages"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: LinkedDropdownComponent, decorators: [{
            type: Component,
            args: [{ selector: 'smz-linked-dropdown', template: "<ng-container *ngIf=\"options$ | async as options\">\r\n\r\n<div class=\"ui-g ui-fluid\">\r\n    <div class=\"ui-g-12 grid-nogutter\" [ngStyle]=\"{ padding: 0 }\">\r\n        <label *ngIf=\"input.hideLabel != true\" class=\"smz__input_name\" [innerHTML]=\"input.name\"></label>\r\n        <div class=\"input_inner__wrapper grid grid-nogutter\">\r\n            <p-dropdown\r\n                fxFlex=\"grow\"\r\n                class=\"col-12 grid-nogutter smz__input_value\"\r\n                [options]=\"options\"\r\n                [formControl]=\"control\"\r\n                optionLabel=\"name\"\r\n                [autoDisplayFirst]=\"false\"\r\n                dataKey=\"id\"\r\n                appendTo=\"body\"\r\n                (onChange)=\"service.setValue(input, formId, $event)\"\r\n                [filter]=\"input.showFilter ? true : false\"\r\n                [filterMatchMode]=\"input.filterMatchMode != null ? input.filterMatchMode : 'contains'\"\r\n                [showClear]=\"input.showClear\"\r\n                [emptyMessage]=\"input.emptyMessage\"\r\n                [emptyFilterMessage]=\"input.emptyFilterMessage\"\r\n                [autofocusFilter]=\"input.autofocusFilter\">\r\n            </p-dropdown>\r\n            <smz-validation-messages [input]=\"input\" [control]=\"control\" [behaviors]=\"behaviors\"></smz-validation-messages>\r\n        </div>\r\n    </div>\r\n</div>\r\n\r\n</ng-container>" }]
        }], ctorParameters: () => [{ type: i1.SmzFormsDropdownService }], propDecorators: { input: [{
                type: Input
            }], formId: [{
                type: Input
            }], control: [{
                type: Input
            }], behaviors: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 