import { Component, DestroyRef, inject, input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { delay } from 'rxjs';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { TooltipDirective } from '@seniorsistemas/angular-components/tooltip';
import { LookupComponent } from '../../../components/lookup/lookup.component';
import { FieldLabelComponent } from '../../../components/field-label/field-label.component';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
export class LookupFieldComponent {
    _destroyRef = inject(DestroyRef);
    gridData = [];
    searchTotalRecords = 0;
    lookupSuggestions = [];
    searchTotalRecordsLabel = '';
    field = input.required();
    formControl = input.required();
    ngOnInit() {
        this.setLookupData();
    }
    setLookupData() {
        const field = this.field();
        field.suggestionsObservable
            .pipe(takeUntilDestroyed(this._destroyRef))
            .subscribe((suggestions) => (this.lookupSuggestions = suggestions));
        field.searchObservable
            .pipe(takeUntilDestroyed(this._destroyRef), delay(0))
            .subscribe(({ totalRecords, gridData, searchTotalRecordsLabel }) => {
            this.gridData = gridData;
            this.searchTotalRecords = totalRecords;
            this.searchTotalRecordsLabel = searchTotalRecordsLabel;
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LookupFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "18.2.14", type: LookupFieldComponent, isStandalone: true, selector: "ng-component", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: true, transformFunction: null }, formControl: { classPropertyName: "formControl", publicName: "formControl", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "@let _field = field();\n<s-field-label [field]=\"_field\"></s-field-label>\n\n<div\n    [sTooltip]=\"_field.tooltip\"\n    tooltipPosition=\"top\"\n    [showDelay]=\"500\"\n>\n    <s-lookup\n        [id]=\"_field.id || _field.name\"\n        [multiple]=\"_field.multiple ?? false\"\n        [formControl]=\"formControl()\"\n        [lookupSuggestions]=\"lookupSuggestions\"\n        [dataKey]=\"_field.dataKey\"\n        [placeholder]=\"_field.placeholder\"\n        [showSearch]=\"_field.showSearch ?? true\"\n        [searchFields]=\"_field.searchFields\"\n        [searchGridFields]=\"_field.searchGridFields\"\n        [searchGridData]=\"gridData\"\n        (onLookupRequest)=\"_field.onLookupRequest($event)\"\n        (onSearchRequest)=\"_field.onSearchRequest($event)\"\n        [lookupDisplayField]=\"_field.lookupDisplayField\"\n        [searchTotalRecords]=\"searchTotalRecords\"\n        [labelOptions]=\"{\n            recordsLabel: _field.recordsLabel,\n            recordLabel: _field.recordLabel,\n            emptyFieldLabel: _field.emptyFieldLabel,\n            selectLabel: _field.selectLabel,\n            cancelLabel: _field.cancelLabel,\n            clearLabel: _field.clearLabel,\n            filterLabel: _field.filterLabel,\n            filterTitle: _field.filterTitle,\n            searchTotalRecordsLabel: searchTotalRecordsLabel,\n            searchEmptyTitle: _field.searchEmptyTitle,\n            searchTitle: _field.searchTitle,\n        }\"\n        (onSelect)=\"_field.onSelect?.($event)\"\n        (onUnselect)=\"_field.onUnselect?.($event)\"\n        (onClear)=\"_field.onClear ? _field.onClear($event) : null\"\n        (onBlur)=\"_field.onBlur ? _field.onBlur($event) : null\"\n        [lookupAppendTo]=\"_field.appendTo\"\n        [lookupEmptyMessage]=\"_field.emptyMessage\"\n        [defaultFilter]=\"_field.defaultFilter ?? []\"\n        [autocompleteForceSelection]=\"_field.autocompleteForceSelection ?? true\"\n        [maxlength]=\"_field.maxlength ?? null\"\n        [alertConfig]=\"_field.alertConfig\"\n        [showAddOption]=\"_field.showAddOption ?? false\"\n        [showEditOption]=\"_field.showEditOption ?? false\"\n        [showRemoveOption]=\"_field.showRemoveOption ?? false\"\n        [sortableColumnsDisabled]=\"_field.sortableColumnsDisabled ?? []\"\n        (onAdd)=\"_field.onAdd ? _field.onAdd() : null\"\n        (onEdit)=\"_field.onEdit ? _field.onEdit($event) : null\"\n        (onRemove)=\"_field.onRemove ? _field.onRemove($event) : null\"\n        (onClearButtonClick)=\"_field.onClearButtonClick ? _field.onClearButtonClick() : null\"\n    >\n    </s-lookup>\n</div>\n\n", dependencies: [{ kind: "component", type: FieldLabelComponent, selector: "s-field-label", inputs: ["field", "fieldContainerRef"] }, { kind: "directive", type: TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }, { kind: "component", type: LookupComponent, selector: "s-lookup", inputs: ["alertConfig", "formControlName", "id", "autocompleteForceSelection", "maxlength", "multiple", "dataKey", "disabled", "showSearch", "lookupSuggestions", "lookupDisplayField", "lookupDisplayFieldTooltip", "lookupEmptyMessage", "lookupAppendTo", "searchEmptyDescription", "searchGridData", "searchTotalRecords", "searchFields", "searchGridFields", "multiSortMeta", "placeholder", "sortableColumnsDisabled", "lookupRowProps", "defaultFilter", "showAddOption", "showEditOption", "showRemoveOption", "dialogFullScreen", "labelOptions"], outputs: ["onLookupRequest", "onSearchRequest", "onFocus", "onBlur", "onKeyUp", "onSelect", "onUnselect", "onClear", "onAdd", "onEdit", "onRemove", "onClearButtonClick"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LookupFieldComponent, decorators: [{
            type: Component,
            args: [{ standalone: true, imports: [FieldLabelComponent, TooltipDirective, LookupComponent, ReactiveFormsModule], template: "@let _field = field();\n<s-field-label [field]=\"_field\"></s-field-label>\n\n<div\n    [sTooltip]=\"_field.tooltip\"\n    tooltipPosition=\"top\"\n    [showDelay]=\"500\"\n>\n    <s-lookup\n        [id]=\"_field.id || _field.name\"\n        [multiple]=\"_field.multiple ?? false\"\n        [formControl]=\"formControl()\"\n        [lookupSuggestions]=\"lookupSuggestions\"\n        [dataKey]=\"_field.dataKey\"\n        [placeholder]=\"_field.placeholder\"\n        [showSearch]=\"_field.showSearch ?? true\"\n        [searchFields]=\"_field.searchFields\"\n        [searchGridFields]=\"_field.searchGridFields\"\n        [searchGridData]=\"gridData\"\n        (onLookupRequest)=\"_field.onLookupRequest($event)\"\n        (onSearchRequest)=\"_field.onSearchRequest($event)\"\n        [lookupDisplayField]=\"_field.lookupDisplayField\"\n        [searchTotalRecords]=\"searchTotalRecords\"\n        [labelOptions]=\"{\n            recordsLabel: _field.recordsLabel,\n            recordLabel: _field.recordLabel,\n            emptyFieldLabel: _field.emptyFieldLabel,\n            selectLabel: _field.selectLabel,\n            cancelLabel: _field.cancelLabel,\n            clearLabel: _field.clearLabel,\n            filterLabel: _field.filterLabel,\n            filterTitle: _field.filterTitle,\n            searchTotalRecordsLabel: searchTotalRecordsLabel,\n            searchEmptyTitle: _field.searchEmptyTitle,\n            searchTitle: _field.searchTitle,\n        }\"\n        (onSelect)=\"_field.onSelect?.($event)\"\n        (onUnselect)=\"_field.onUnselect?.($event)\"\n        (onClear)=\"_field.onClear ? _field.onClear($event) : null\"\n        (onBlur)=\"_field.onBlur ? _field.onBlur($event) : null\"\n        [lookupAppendTo]=\"_field.appendTo\"\n        [lookupEmptyMessage]=\"_field.emptyMessage\"\n        [defaultFilter]=\"_field.defaultFilter ?? []\"\n        [autocompleteForceSelection]=\"_field.autocompleteForceSelection ?? true\"\n        [maxlength]=\"_field.maxlength ?? null\"\n        [alertConfig]=\"_field.alertConfig\"\n        [showAddOption]=\"_field.showAddOption ?? false\"\n        [showEditOption]=\"_field.showEditOption ?? false\"\n        [showRemoveOption]=\"_field.showRemoveOption ?? false\"\n        [sortableColumnsDisabled]=\"_field.sortableColumnsDisabled ?? []\"\n        (onAdd)=\"_field.onAdd ? _field.onAdd() : null\"\n        (onEdit)=\"_field.onEdit ? _field.onEdit($event) : null\"\n        (onRemove)=\"_field.onRemove ? _field.onRemove($event) : null\"\n        (onClearButtonClick)=\"_field.onClearButtonClick ? _field.onClearButtonClick() : null\"\n    >\n    </s-lookup>\n</div>\n\n" }]
        }] });
//# sourceMappingURL=data:application/json;base64, 