import { Component, Input } from '@angular/core';
import { of, tap } from 'rxjs';
import { CONTROL_FUNCTIONS } from '../../models/control-type-functions';
import { getFirstElement } from '../../../../common/utils/utils';
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/api";
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 "primeng/tooltip";
import * as i8 from "primeng/treeselect";
import * as i9 from "../validation-messages/validation-messages.component";
import * as i10 from "../../../../common/data-pipes/pipes/safe-html.pipe";
export class InputTreeComponent {
    constructor(service) {
        this.service = service;
    }
    ngOnInit() {
        if (this.input.dependsOn != null) {
            // Com dependencia: se registrar no serviço que ouve outros eventos
            this.service.registryObserver(this.input, this.formId);
        }
        this.service.registryDependsOnData(this.input, this.formId);
    }
    ngAfterViewInit() {
        if (this.input.dependsOn != null) {
            // Com dependencia: ouvir mudanças no serviço de dropdown
            this.nodes$ = this.service.observers[this.formId + this.input.propertyName]?.options
                .pipe(tap((nodes) => {
                this.input.currentNodes = nodes;
                setTimeout(() => {
                    CONTROL_FUNCTIONS[this.input.type].applyDefaultValue(this.control, this.input);
                }, 0);
            }));
        }
        else {
            // Sem dependencia: assumir que o primeiro elemento do array é a árvore
            this.input.currentNodes = getFirstElement(this.input.options)?.data;
            this.nodes$ = of(this.input.currentNodes);
            setTimeout(() => {
                CONTROL_FUNCTIONS[this.input.type].applyDefaultValue(this.control, this.input);
            }, 0);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: InputTreeComponent, deps: [{ token: i1.SmzFormsDropdownService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.5", type: InputTreeComponent, selector: "smz-input-tree", inputs: { input: "input", formId: "formId", control: "control", behaviors: "behaviors" }, ngImport: i0, template: "<ng-container *ngIf=\"nodes$ | async as nodes\">\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-treeSelect\r\n          fxFlex=\"grow\"\r\n          class=\"col-12 grid-nogutter smz__input_value\"\r\n          containerStyleClass=\"w-full\"\r\n          [formControl]=\"control\"\r\n          [options]=\"nodes\"\r\n          [placeholder]=\"input.name\"\r\n          appendTo=\"body\"\r\n          [filter]=\"input.showFilter ? true : false\"\r\n          [selectionMode]=\"input.selectionMode\"\r\n          [filterInputAutoFocus]=\"input.autofocusFilter\"\r\n          [emptyMessage]=\"input.emptyMessage\"\r\n          [showClear]=\"input.showClear\"\r\n          [filterPlaceholder]=\"input.emptyFilterMessage\"\r\n          [scrollHeight]=\"input.scrollHeight\"\r\n          [display]=\"input.display\"\r\n          >\r\n          <ng-container *ngFor=\"let inputType of input.allTypes\">\r\n            <ng-template let-node [pTemplate]=\"inputType\">\r\n              <div [innerHTML]=\"node.label | safeHtml\" [pTooltip]=\"node.tooltip\"></div>\r\n            </ng-template>\r\n        </ng-container>\r\n        </p-treeSelect>\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.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i3.PrimeTemplate, selector: "[pTemplate]", inputs: ["type", "pTemplate"] }, { 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: "directive", type: i7.Tooltip, selector: "[pTooltip]", inputs: ["tooltipPosition", "tooltipEvent", "appendTo", "positionStyle", "tooltipStyleClass", "tooltipZIndex", "escape", "showDelay", "hideDelay", "life", "positionTop", "positionLeft", "autoHide", "fitContent", "hideOnEscape", "pTooltip", "tooltipDisabled", "tooltipOptions"] }, { kind: "component", type: i8.TreeSelect, selector: "p-treeSelect", inputs: ["inputId", "scrollHeight", "disabled", "metaKeySelection", "display", "selectionMode", "tabindex", "ariaLabel", "ariaLabelledBy", "placeholder", "panelClass", "panelStyle", "panelStyleClass", "containerStyle", "containerStyleClass", "labelStyle", "labelStyleClass", "overlayOptions", "emptyMessage", "appendTo", "filter", "filterBy", "filterMode", "filterPlaceholder", "filterLocale", "filterInputAutoFocus", "propagateSelectionDown", "propagateSelectionUp", "showClear", "resetFilterOnHide", "virtualScroll", "virtualScrollItemSize", "virtualScrollOptions", "autofocus", "options", "showTransitionOptions", "hideTransitionOptions"], outputs: ["onNodeExpand", "onNodeCollapse", "onShow", "onHide", "onClear", "onFilter", "onNodeUnselect", "onNodeSelect"] }, { kind: "component", type: i9.ValidationMessagesComponent, selector: "smz-validation-messages", inputs: ["input", "control", "behaviors", "extraMessages"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }, { kind: "pipe", type: i10.SafeHtmlPipe, name: "safeHtml" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: InputTreeComponent, decorators: [{
            type: Component,
            args: [{ selector: 'smz-input-tree', template: "<ng-container *ngIf=\"nodes$ | async as nodes\">\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-treeSelect\r\n          fxFlex=\"grow\"\r\n          class=\"col-12 grid-nogutter smz__input_value\"\r\n          containerStyleClass=\"w-full\"\r\n          [formControl]=\"control\"\r\n          [options]=\"nodes\"\r\n          [placeholder]=\"input.name\"\r\n          appendTo=\"body\"\r\n          [filter]=\"input.showFilter ? true : false\"\r\n          [selectionMode]=\"input.selectionMode\"\r\n          [filterInputAutoFocus]=\"input.autofocusFilter\"\r\n          [emptyMessage]=\"input.emptyMessage\"\r\n          [showClear]=\"input.showClear\"\r\n          [filterPlaceholder]=\"input.emptyFilterMessage\"\r\n          [scrollHeight]=\"input.scrollHeight\"\r\n          [display]=\"input.display\"\r\n          >\r\n          <ng-container *ngFor=\"let inputType of input.allTypes\">\r\n            <ng-template let-node [pTemplate]=\"inputType\">\r\n              <div [innerHTML]=\"node.label | safeHtml\" [pTooltip]=\"node.tooltip\"></div>\r\n            </ng-template>\r\n        </ng-container>\r\n        </p-treeSelect>\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, 