import { animate, state, style, transition, trigger } from '@angular/animations';
import { ChangeDetectorRef, Component, ContentChildren, EventEmitter, Input, Output, ViewChild, inject } from '@angular/core';
import { GlobalSearchDropdownItemComponent } from './components/dropdown/global-search-dropdown-item.component';
import { isNullOrUndefined } from '@seniorsistemas/angular-components/utils';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "primeng/inputtext";
import * as i3 from "@angular/forms";
import * as i4 from "@seniorsistemas/angular-components/button";
import * as i5 from "@seniorsistemas/angular-components/loading-state";
import * as i6 from "@seniorsistemas/angular-components/empty-state";
/**
 * @description Componente de busca global com input, dropdown de resultados, estado
 * de carregamento, empty state e suporte a itens customizáveis via `GlobalSearchDropdownItemComponent`.
 *
 * @example
 * ```html
 * <s-global-search
 *   totalItensLabel="resultados"
 *   showMoreLabel="Ver mais"
 *   [totalElements]="total"
 *   (search)="onBusca($event)" />
 * ```
 *
 * @category Structure
 */
export class GlobalSearchComponent {
    _cdr = inject(ChangeDetectorRef);
    static nextId = 0;
    globalSearch = null;
    /** @description Identificador único do componente no DOM. Gerado automaticamente se não informado. */
    id = `s-global-search-${GlobalSearchDropdownItemComponent.nextId++}`;
    /** @description Tempo de debounce em ms antes de emitir o evento de busca. @default 500 */
    delay = 500;
    /** @description Label que acompanha o total de resultados. Campo obrigatório. */
    totalItensLabel;
    /** @description Rótulo do link para exibir mais resultados. Campo obrigatório. */
    showMoreLabel;
    /** @description Placeholder do input de busca. */
    placeholder;
    /** @description Exibe indicador de carregamento no dropdown. @default false */
    isLoading = false;
    /** @description Número total de resultados encontrados. */
    totalElements;
    /** @description Título do empty state quando não há resultados. */
    emptyTitle;
    /** @description Descrição do empty state exibida abaixo do título. */
    emptyDescription;
    /** @description Classe do ícone exibido no empty state. */
    emptyIcon;
    /** @description Exibe o rodapé com o link "ver mais" e contagem de resultados. @default true */
    showFooter = true;
    dropdownItens = null;
    /** @description Emitido ao digitar no campo de busca, com o valor atual da pesquisa. */
    searched = new EventEmitter();
    /** @description Emitido quando o campo de busca ganha ou perde foco (`true` = focado). */
    focused = new EventEmitter();
    /** @description Emitido ao clicar no link para exibir mais resultados. */
    moreShown = new EventEmitter();
    search = null;
    wasSearched = false;
    isModalLoading = false;
    expanded = true;
    onChange() {
        const search = this.search;
        setTimeout(() => {
            if (this.search === search) {
                this._canShowGlobalSearchActive();
                this.searched.emit(this.search ?? '');
            }
        }, this.delay);
    }
    focusIn() {
        this.focused.emit(true);
    }
    focusOut() {
        this.focused.emit(false);
    }
    showMore() {
        this.moreShown.emit();
    }
    close() {
        this.search = null;
        this.wasSearched = false;
        this.dropdownItens = null;
        this.isModalLoading = false;
        this._removeActiveClassByGlobalSearch();
    }
    _removeActiveClassByGlobalSearch() {
        if (isNullOrUndefined(this.globalSearch))
            return;
        this.globalSearch.nativeElement.classList.remove('global-search__input-active');
    }
    _canShowGlobalSearchActive() {
        this.wasSearched = !!this.search;
        if (this.search) {
            if (isNullOrUndefined(this.globalSearch))
                return;
            this.globalSearch.nativeElement.classList.add('global-search__input-active');
        }
        else {
            this._removeActiveClassByGlobalSearch();
            this.close();
        }
        this._cdr.detectChanges();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: GlobalSearchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: GlobalSearchComponent, selector: "s-global-search", inputs: { id: "id", delay: "delay", totalItensLabel: "totalItensLabel", showMoreLabel: "showMoreLabel", placeholder: "placeholder", isLoading: "isLoading", totalElements: "totalElements", emptyTitle: "emptyTitle", emptyDescription: "emptyDescription", emptyIcon: "emptyIcon", showFooter: "showFooter" }, outputs: { searched: "searched", focused: "focused", moreShown: "moreShown" }, queries: [{ propertyName: "dropdownItens", predicate: GlobalSearchDropdownItemComponent }], viewQueries: [{ propertyName: "globalSearch", first: true, predicate: ["globalSearch"], descendants: true }], ngImport: i0, template: "<div class=\"p-inputGroup\">\n    <input\n        #globalSearch\n        class=\"global-search__input\"\n        [(ngModel)]=\"search\"\n        (ngModelChange)=\"onChange()\"\n        pInputText\n        [placeholder]=\"placeholder\"\n        (focus)=\"focusIn()\"\n        (blur)=\"focusOut()\"\n    />\n    <span class=\"p-inputGroup-addon global-search__span\">\n        <em class=\"fas fa-search\"></em>\n    </span>\n\n    @if (wasSearched) {\n        <div class=\"global-search__modal\">\n            <div\n                *sLoadingState=\"isLoading && !isModalLoading\"\n                class=\"global-search__loader\"\n            >\n                @if ((dropdownItens && dropdownItens.length > 0) || isLoading) {\n                    <div class=\"global-search__container\">\n                        @if (dropdownItens && dropdownItens.length > 0) {\n                            <div>\n                                <div class=\"global-search__modal--total-itens-title\">\n                                    <span class=\"ui-grid-col-11 no-space\">{{ totalItensLabel }}</span>\n                                    <span\n                                        class=\"ui-grid-col-1 no-space global-search__modal--total-itens-title-icon\"\n                                        (click)=\"close()\"\n                                    >\n                                        <em class=\"fas fa-times\"></em>\n                                    </span>\n                                </div>\n                                <div\n                                    class=\"no-space global-search__dropdown--itens\"\n                                    [@expandableContent]=\"expanded\"\n                                >\n                                    @for (item of dropdownItens; track item.id) {\n                                        <div class=\"s-object-card-field no-space global-search__dropdown--itens-container\">\n                                            <ng-container *ngTemplateOutlet=\"item.content\"></ng-container>\n                                        </div>\n                                    }\n                                </div>\n\n                                @if (showFooter) {\n                                    <div class=\"ui-grid-col-12 global-search__modal--footer\">\n                                        <s-button\n                                            class=\"global-search__show-more\"\n                                            (click)=\"showMore()\"\n                                            priority=\"link\"\n                                        >\n                                            {{ showMoreLabel }}\n                                        </s-button>\n                                    </div>\n                                }\n                            </div>\n                        }\n                    </div>\n                }\n\n                @if ((!dropdownItens || !dropdownItens.length) && !isLoading) {\n                    <s-empty-state\n                        [title]=\"emptyTitle ?? ''\"\n                        [description]=\"emptyDescription\"\n                        ngClass=\"global-search__empty-state--icon\"\n                        [iconClass]=\"emptyIcon ? emptyIcon : 'fas fa-search'\"\n                    >\n                    </s-empty-state>\n                }\n            </div>\n        </div>\n    }\n\n    @if (wasSearched) {\n        <div\n            class=\"global-search__background\"\n            (click)=\"close()\"\n        ></div>\n    }\n</div>\n", styles: [".p-inputGroup{display:flex;max-width:100%}.global-search__input{border-radius:20px 0 0 20px;border-right:none;cursor:pointer;height:25px;min-height:25px;padding:0 0 0 15px;transition:all .3s;width:136px}.global-search__input:active,.global-search__input:focus,.global-search__input-active{border-bottom:solid 1px #428bca;border-left:solid 1px #428bca;border-top:solid 1px #428bca;cursor:default;transition:all .3s;width:466px}.global-search__input:active,.global-search__input:focus+.global-search__span{border-bottom:solid 1px #428bca;border-left:none;border-right:solid 1px #428bca;border-top:solid 1px #428bca;transition:all .3s}.global-search__span{align-items:center;background:transparent;border:1px solid #ccc;border-left:none;border-radius:0 20px 20px 0;display:flex;height:25px;justify-content:center;padding:0 8px;transition:all .3s}.global-search__modal{background:#fff;border-radius:5px;box-shadow:0 2px 8px #0006;margin-top:60px;min-height:50px;position:absolute;width:500px;z-index:6}.global-search__modal--total-itens-title{border-bottom:solid 1px #ccc;color:#333;font-weight:600;height:50px;padding:15px}.global-search__modal--footer{border-top:solid 1px #ccc;height:50px}.global-search__modal--total-itens-title-icon{cursor:pointer;text-align:right}.global-search__container{min-height:50px;width:100%}.global-search__dropdown--itens{max-height:510px;overflow:auto}.global-search__dropdown--itens-container:hover{background:#dbe0e4}.global-search__background{background:#0006;cursor:pointer;height:calc(100vh - 70px);left:0;margin-top:50px;position:absolute;width:100%;z-index:5}.no-space{margin:0;padding:0}.global-search__show-more{display:flex;flex-direction:column}.global-search__show-more--button{color:#428bca!important}.modal{height:calc(100vh - 90px);left:1%;position:absolute;width:98%}.global-search__empty-state--icon{margin:42px 134px}::ng-deep s-global-search{width:100%}::ng-deep s-global-search .global-search__loader{border-radius:5px!important;width:100%}::ng-deep s-global-search .global-search__empty-state--icon .empty-state .icon{font-size:40px}::ng-deep s-global-search .s-button-priority-link{color:#428bca}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.InputText, selector: "[pInputText]", inputs: ["variant", "fluid", "pSize"] }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i4.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: i5.LoadingStateDirective, selector: "[sLoadingState]", inputs: ["sLoadingState"] }, { kind: "component", type: i6.EmptyStateComponent, selector: "s-empty-state", inputs: ["id", "title", "iconClass", "description", "showPrimaryAction", "showSecondaryAction", "primaryActionLabel", "secondaryActionLabel", "primaryModel"], outputs: ["primaryAction", "secondaryAction"] }], animations: [
            trigger('expandableContent', [
                state('*', style({ height: '0' })),
                state('false', style({ height: '0' })),
                state('true', style({ height: '*' })),
                transition('* => true', animate('200ms ease-out')),
                transition('false <=> true', animate('200ms ease-out')),
            ]),
        ] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: GlobalSearchComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-global-search', animations: [
                        trigger('expandableContent', [
                            state('*', style({ height: '0' })),
                            state('false', style({ height: '0' })),
                            state('true', style({ height: '*' })),
                            transition('* => true', animate('200ms ease-out')),
                            transition('false <=> true', animate('200ms ease-out')),
                        ]),
                    ], template: "<div class=\"p-inputGroup\">\n    <input\n        #globalSearch\n        class=\"global-search__input\"\n        [(ngModel)]=\"search\"\n        (ngModelChange)=\"onChange()\"\n        pInputText\n        [placeholder]=\"placeholder\"\n        (focus)=\"focusIn()\"\n        (blur)=\"focusOut()\"\n    />\n    <span class=\"p-inputGroup-addon global-search__span\">\n        <em class=\"fas fa-search\"></em>\n    </span>\n\n    @if (wasSearched) {\n        <div class=\"global-search__modal\">\n            <div\n                *sLoadingState=\"isLoading && !isModalLoading\"\n                class=\"global-search__loader\"\n            >\n                @if ((dropdownItens && dropdownItens.length > 0) || isLoading) {\n                    <div class=\"global-search__container\">\n                        @if (dropdownItens && dropdownItens.length > 0) {\n                            <div>\n                                <div class=\"global-search__modal--total-itens-title\">\n                                    <span class=\"ui-grid-col-11 no-space\">{{ totalItensLabel }}</span>\n                                    <span\n                                        class=\"ui-grid-col-1 no-space global-search__modal--total-itens-title-icon\"\n                                        (click)=\"close()\"\n                                    >\n                                        <em class=\"fas fa-times\"></em>\n                                    </span>\n                                </div>\n                                <div\n                                    class=\"no-space global-search__dropdown--itens\"\n                                    [@expandableContent]=\"expanded\"\n                                >\n                                    @for (item of dropdownItens; track item.id) {\n                                        <div class=\"s-object-card-field no-space global-search__dropdown--itens-container\">\n                                            <ng-container *ngTemplateOutlet=\"item.content\"></ng-container>\n                                        </div>\n                                    }\n                                </div>\n\n                                @if (showFooter) {\n                                    <div class=\"ui-grid-col-12 global-search__modal--footer\">\n                                        <s-button\n                                            class=\"global-search__show-more\"\n                                            (click)=\"showMore()\"\n                                            priority=\"link\"\n                                        >\n                                            {{ showMoreLabel }}\n                                        </s-button>\n                                    </div>\n                                }\n                            </div>\n                        }\n                    </div>\n                }\n\n                @if ((!dropdownItens || !dropdownItens.length) && !isLoading) {\n                    <s-empty-state\n                        [title]=\"emptyTitle ?? ''\"\n                        [description]=\"emptyDescription\"\n                        ngClass=\"global-search__empty-state--icon\"\n                        [iconClass]=\"emptyIcon ? emptyIcon : 'fas fa-search'\"\n                    >\n                    </s-empty-state>\n                }\n            </div>\n        </div>\n    }\n\n    @if (wasSearched) {\n        <div\n            class=\"global-search__background\"\n            (click)=\"close()\"\n        ></div>\n    }\n</div>\n", styles: [".p-inputGroup{display:flex;max-width:100%}.global-search__input{border-radius:20px 0 0 20px;border-right:none;cursor:pointer;height:25px;min-height:25px;padding:0 0 0 15px;transition:all .3s;width:136px}.global-search__input:active,.global-search__input:focus,.global-search__input-active{border-bottom:solid 1px #428bca;border-left:solid 1px #428bca;border-top:solid 1px #428bca;cursor:default;transition:all .3s;width:466px}.global-search__input:active,.global-search__input:focus+.global-search__span{border-bottom:solid 1px #428bca;border-left:none;border-right:solid 1px #428bca;border-top:solid 1px #428bca;transition:all .3s}.global-search__span{align-items:center;background:transparent;border:1px solid #ccc;border-left:none;border-radius:0 20px 20px 0;display:flex;height:25px;justify-content:center;padding:0 8px;transition:all .3s}.global-search__modal{background:#fff;border-radius:5px;box-shadow:0 2px 8px #0006;margin-top:60px;min-height:50px;position:absolute;width:500px;z-index:6}.global-search__modal--total-itens-title{border-bottom:solid 1px #ccc;color:#333;font-weight:600;height:50px;padding:15px}.global-search__modal--footer{border-top:solid 1px #ccc;height:50px}.global-search__modal--total-itens-title-icon{cursor:pointer;text-align:right}.global-search__container{min-height:50px;width:100%}.global-search__dropdown--itens{max-height:510px;overflow:auto}.global-search__dropdown--itens-container:hover{background:#dbe0e4}.global-search__background{background:#0006;cursor:pointer;height:calc(100vh - 70px);left:0;margin-top:50px;position:absolute;width:100%;z-index:5}.no-space{margin:0;padding:0}.global-search__show-more{display:flex;flex-direction:column}.global-search__show-more--button{color:#428bca!important}.modal{height:calc(100vh - 90px);left:1%;position:absolute;width:98%}.global-search__empty-state--icon{margin:42px 134px}::ng-deep s-global-search{width:100%}::ng-deep s-global-search .global-search__loader{border-radius:5px!important;width:100%}::ng-deep s-global-search .global-search__empty-state--icon .empty-state .icon{font-size:40px}::ng-deep s-global-search .s-button-priority-link{color:#428bca}\n"] }]
        }], propDecorators: { globalSearch: [{
                type: ViewChild,
                args: ['globalSearch', { static: false }]
            }], id: [{
                type: Input
            }], delay: [{
                type: Input
            }], totalItensLabel: [{
                type: Input,
                args: [{ required: true }]
            }], showMoreLabel: [{
                type: Input,
                args: [{ required: true }]
            }], placeholder: [{
                type: Input
            }], isLoading: [{
                type: Input
            }], totalElements: [{
                type: Input
            }], emptyTitle: [{
                type: Input
            }], emptyDescription: [{
                type: Input
            }], emptyIcon: [{
                type: Input
            }], showFooter: [{
                type: Input
            }], dropdownItens: [{
                type: ContentChildren,
                args: [GlobalSearchDropdownItemComponent]
            }], searched: [{
                type: Output
            }], focused: [{
                type: Output
            }], moreShown: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 