import * as i0 from '@angular/core';
import { inject, ChangeDetectorRef, EventEmitter, forwardRef, Component, Input, Output, NgModule } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@seniorsistemas/angular-components/tiered-menu';
import { TieredMenuModule } from '@seniorsistemas/angular-components/tiered-menu';
import * as i3 from '@seniorsistemas/angular-components/tooltip';
import { TooltipModule } from '@seniorsistemas/angular-components/tooltip';

/**
 * @description Componente de navegação por etapas que exibe o estado atual (step)
 * com suporte a avanço, retrocesso e seleção direta via dropdown (`TieredMenu`).
 * Implementa `ControlValueAccessor` para integração com formulários Angular.
 *
 * @example
 * ```html
 * <s-navigation-button
 *   [steps]="etapas"
 *   (stepChanged)="onEtapaMudou($event)" />
 * ```
 *
 * @category Inputs
 */
class NavigationButtonComponent {
    changeDetectorRef = inject(ChangeDetectorRef);
    /** @description Lista de etapas de navegação. Campo obrigatório. */
    steps;
    /** @description Valor padrão a ser selecionado ao inicializar o componente. */
    defaultValue;
    /** @description Texto exibido no tooltip do botão principal. */
    tooltip;
    /** @description Quando `true`, emite `stepChanged` durante a inicialização com a etapa atual. @default false */
    changeOnInit = false;
    /** @description Emitido quando o usuário navega para uma nova etapa, com informações da etapa anterior e atual. */
    stepChanged = new EventEmitter();
    currentIndex = 0;
    isDisabled = false;
    tieredMenuItems = [];
    _onChange;
    _onTouched;
    _value;
    ngOnInit() {
        this._createTieredMenuItems();
        if (this.changeOnInit) {
            this.stepChanged.emit({
                previous: null,
                current: this.steps[this.currentIndex],
            });
        }
    }
    ngAfterViewInit() {
        this._setDefaultValue();
    }
    _setDefaultValue() {
        if (this.defaultValue) {
            this._value = this.defaultValue;
            const index = this.steps.findIndex((step) => step.value === this._value);
            this.currentIndex = index !== -1 ? index : 0;
            this.stepChanged.emit({
                previous: null,
                current: this.steps[this.currentIndex],
            });
            this.changeDetectorRef.detectChanges();
        }
    }
    writeValue(value) {
        this._value = value;
        const index = this.steps.findIndex((step) => step.value === this._value);
        this.currentIndex = index !== -1 ? index : 0;
    }
    registerOnChange(onChange) {
        this._onChange = onChange;
    }
    registerOnTouched(onTouched) {
        this._onTouched = onTouched;
    }
    setDisabledState(isDisabled) {
        this.isDisabled = isDisabled;
    }
    onNext() {
        if (this.isDisabled)
            return;
        const previous = this.steps[this.currentIndex];
        if (this.currentIndex < this.steps.length - 1) {
            this.currentIndex++;
            const current = this.steps[this.currentIndex];
            this._onChange && this._onChange(current.value);
            this.stepChanged.emit({ previous, current });
        }
        this._onTouched && this._onTouched();
    }
    onPrevious() {
        if (this.isDisabled)
            return;
        const previous = this.steps[this.currentIndex];
        if (this.currentIndex > 0) {
            this.currentIndex--;
            const current = this.steps[this.currentIndex];
            this._onChange && this._onChange(current.value);
            this.stepChanged.emit({ previous, current });
        }
        this._onTouched && this._onTouched();
    }
    _createTieredMenuItems() {
        this.steps.forEach((step) => {
            this.tieredMenuItems.push({
                label: step.label,
                command: () => {
                    const index = this.steps.findIndex((s) => s === step);
                    if (this.currentIndex !== index) {
                        this._onChange && this._onChange(step.value);
                        this.stepChanged.emit({
                            previous: this.steps[this.currentIndex],
                            current: step,
                        });
                        this.currentIndex = index;
                    }
                    this._onTouched && this._onTouched();
                },
            });
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: NavigationButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: NavigationButtonComponent, selector: "s-navigation-button", inputs: { steps: "steps", defaultValue: "defaultValue", tooltip: "tooltip", changeOnInit: "changeOnInit" }, outputs: { stepChanged: "stepChanged" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => NavigationButtonComponent),
                multi: true,
            },
        ], ngImport: i0, template: "<div\n    class=\"navigation-button\"\n    [ngClass]=\"{ 'navigation-button--disabled': isDisabled }\"\n>\n    <button\n        class=\"option option--previous\"\n        [ngClass]=\"{ 'option--disabled': currentIndex === 0 }\"\n        (click)=\"onPrevious()\"\n    >\n        <i class=\"fas fa-chevron-left\"></i>\n    </button>\n\n    @if (steps[currentIndex].tooltip || tooltip) {\n        <button\n            [sTooltip]=\"steps[currentIndex].tooltip || tooltip\"\n            class=\"step\"\n            sTieredMenu\n            [items]=\"tieredMenuItems\"\n            [focusedItem]=\"tieredMenuItems[currentIndex]\"\n        >\n            {{ steps[currentIndex].label }}\n        </button>\n    } @else {\n        <button class=\"step\">\n            {{ steps[currentIndex].label }}\n        </button>\n    }\n    <button\n        class=\"option option--next\"\n        [ngClass]=\"{ 'option--disabled': currentIndex === steps.length - 1 }\"\n        (click)=\"onNext()\"\n    >\n        <i class=\"fas fa-chevron-right\"></i>\n    </button>\n</div>\n", styles: [".navigation-button{display:inline-flex}.navigation-button .option,.navigation-button .step{background-color:#428bca;border:none;color:#fff}.navigation-button:not(.navigation-button--disabled) .step{cursor:pointer}.navigation-button:not(.navigation-button--disabled) .step:hover{background-color:#063951}.navigation-button .option{padding:8px 12px}.navigation-button .option--previous{border-radius:16px 0 0 16px}.navigation-button .option--next{border-radius:0 16px 16px 0}.navigation-button .option--disabled{opacity:.5}.navigation-button .option:not(.option--disabled):hover{cursor:pointer;background-color:#063951}.navigation-button .step{font-family:Open Sans,sans-serif;font-size:14px;padding:8px 16px;text-align:center}.navigation-button--disabled{opacity:.5}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.TieredMenuDirective, selector: "[sTieredMenu]", inputs: ["items", "focusedItem", "triggerEvent", "ariaLabel"], outputs: ["tieredMenuOpened", "tieredMenuClosed"] }, { kind: "directive", type: i3.TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: NavigationButtonComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-navigation-button', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => NavigationButtonComponent),
                            multi: true,
                        },
                    ], template: "<div\n    class=\"navigation-button\"\n    [ngClass]=\"{ 'navigation-button--disabled': isDisabled }\"\n>\n    <button\n        class=\"option option--previous\"\n        [ngClass]=\"{ 'option--disabled': currentIndex === 0 }\"\n        (click)=\"onPrevious()\"\n    >\n        <i class=\"fas fa-chevron-left\"></i>\n    </button>\n\n    @if (steps[currentIndex].tooltip || tooltip) {\n        <button\n            [sTooltip]=\"steps[currentIndex].tooltip || tooltip\"\n            class=\"step\"\n            sTieredMenu\n            [items]=\"tieredMenuItems\"\n            [focusedItem]=\"tieredMenuItems[currentIndex]\"\n        >\n            {{ steps[currentIndex].label }}\n        </button>\n    } @else {\n        <button class=\"step\">\n            {{ steps[currentIndex].label }}\n        </button>\n    }\n    <button\n        class=\"option option--next\"\n        [ngClass]=\"{ 'option--disabled': currentIndex === steps.length - 1 }\"\n        (click)=\"onNext()\"\n    >\n        <i class=\"fas fa-chevron-right\"></i>\n    </button>\n</div>\n", styles: [".navigation-button{display:inline-flex}.navigation-button .option,.navigation-button .step{background-color:#428bca;border:none;color:#fff}.navigation-button:not(.navigation-button--disabled) .step{cursor:pointer}.navigation-button:not(.navigation-button--disabled) .step:hover{background-color:#063951}.navigation-button .option{padding:8px 12px}.navigation-button .option--previous{border-radius:16px 0 0 16px}.navigation-button .option--next{border-radius:0 16px 16px 0}.navigation-button .option--disabled{opacity:.5}.navigation-button .option:not(.option--disabled):hover{cursor:pointer;background-color:#063951}.navigation-button .step{font-family:Open Sans,sans-serif;font-size:14px;padding:8px 16px;text-align:center}.navigation-button--disabled{opacity:.5}\n"] }]
        }], propDecorators: { steps: [{
                type: Input,
                args: [{ required: true }]
            }], defaultValue: [{
                type: Input
            }], tooltip: [{
                type: Input
            }], changeOnInit: [{
                type: Input
            }], stepChanged: [{
                type: Output
            }] } });

class NavigationButtonModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: NavigationButtonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: NavigationButtonModule, declarations: [NavigationButtonComponent], imports: [CommonModule, TieredMenuModule, TooltipModule], exports: [NavigationButtonComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: NavigationButtonModule, imports: [CommonModule, TieredMenuModule, TooltipModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: NavigationButtonModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [CommonModule, TieredMenuModule, TooltipModule],
                    declarations: [NavigationButtonComponent],
                    exports: [NavigationButtonComponent],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { NavigationButtonComponent, NavigationButtonModule };
//# sourceMappingURL=seniorsistemas-angular-components-navigation-button.mjs.map
