import * as i0 from '@angular/core';
import { input, inject, Component, Input, NgModule } from '@angular/core';
import * as i3 from '@angular/router';
import { Router, RouterModule, ActivatedRoute, NavigationEnd, PRIMARY_OUTLET } from '@angular/router';
import * as i1$1 from '@seniorsistemas/angular-components/common/deprecated-selector';
import { DEPRECATED_CONFIG, DeprecatedSelectorDirective } from '@seniorsistemas/angular-components/common/deprecated-selector';
import { Subject } from 'rxjs';
import { takeUntil, filter } from 'rxjs/operators';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@ngx-translate/core';
import { TranslateModule } from '@ngx-translate/core';
import { InteractiveContentDirective } from '@seniorsistemas/angular-components/interactive-content';

/**
 * @description Componente de trilha de navegação (breadcrumb) que detecta automaticamente
 * a rota ativa do Angular Router e constrói o caminho hierárquico de páginas.
 * Cada segmento da rota precisa ter a propriedade `routeTitle` definida nos `data` da rota.
 *
 * @example
 * ```html
 * <s-breadcrumb homeUrl="/home" targetHomeUrl="_self" />
 * ```
 *
 * @category Navegação
 */
class BreadcrumbListComponent {
    items = input.required();
    router = inject(Router);
    onActivateRoute(activatedBreadcrumb) {
        if (!activatedBreadcrumb.routerLink || activatedBreadcrumb.disabled) {
            return;
        }
        const routerLink = Array.isArray(activatedBreadcrumb.routerLink)
            ? activatedBreadcrumb.routerLink
            : [activatedBreadcrumb.routerLink];
        if (activatedBreadcrumb.queryParams) {
            this.router.navigate(routerLink, { queryParams: activatedBreadcrumb.queryParams });
        }
        else {
            this.router.navigate(routerLink, { queryParamsHandling: 'preserve' });
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: BreadcrumbListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: BreadcrumbListComponent, isStandalone: true, selector: "s-breadcrumb-list", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "<nav\n    [attr.aria-label]=\"'platform.angular_components.breadcrumb_aria_label' | translate\"\n    class=\"mb-4 mt-4\"\n>\n    <ol class=\"flex select-none flex-wrap items-center gap-3 pb-3 pt-3 [&_li]:font-open-sans [&_li]:text-sm\">\n        @for (breadcrumbItem of items(); track $index; let first = $first; let last = $last) {\n            <li class=\"flex items-center gap-3\">\n                @if (!first) {\n                    <i\n                        class=\"fas fa-chevron-right\"\n                        aria-hidden=\"true\"\n                    ></i>\n                }\n\n                <ng-template #iconTemplate>\n                    <i\n                        [class]=\"breadcrumbItem.icon + (first ? ' text-criticality-blue' : '')\"\n                        aria-hidden=\"true\"\n                    ></i>\n                </ng-template>\n\n                @if (first && breadcrumbItem.icon && breadcrumbItem.disabledIcon) {\n                    <span\n                        class=\"flex items-center gap-1\"\n                        aria-hidden=\"true\"\n                    >\n                        <i\n                            [class]=\"breadcrumbItem.icon + ' text-grayscale-30'\"\n                            aria-hidden=\"true\"\n                        ></i>\n                    </span>\n                }\n\n                @if (breadcrumbItem.url) {\n                    <a\n                        [href]=\"breadcrumbItem.url\"\n                        [target]=\"breadcrumbItem.target\"\n                        class=\"flex items-center gap-1 text-criticality-blue\"\n                        [attr.aria-current]=\"last ? 'page' : null\"\n                        [attr.aria-label]=\"\n                            (first ? 'In\u00EDcio: ' : 'Navegar para ') +\n                            breadcrumbItem.label +\n                            (last ? ' (p\u00E1gina atual)' : '')\n                        \"\n                    >\n                        @if (breadcrumbItem.icon && !(first && breadcrumbItem.disabledIcon)) {\n                            <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n                        }\n                        @if (breadcrumbItem.label && !breadcrumbItem.hideLabel && !first) {\n                            <span>{{ breadcrumbItem.label }}</span>\n                            <span class=\"sr-only\"> (link externo)</span>\n                        }\n                    </a>\n                } @else if (breadcrumbItem.routerLink && !breadcrumbItem.disabled) {\n                    <a\n                        [routerLink]=\"breadcrumbItem.routerLink\"\n                        [queryParams]=\"breadcrumbItem.queryParams\"\n                        [queryParamsHandling]=\"breadcrumbItem.queryParams ? null : 'preserve'\"\n                        [target]=\"breadcrumbItem.target\"\n                        (sInteractiveContent)=\"onActivateRoute(breadcrumbItem)\"\n                        class=\"flex cursor-pointer items-center gap-1 text-primary hover:no-underline\"\n                        [attr.aria-current]=\"last ? 'page' : null\"\n                        [attr.aria-label]=\"\n                            (first ? 'In\u00EDcio: ' : '') + breadcrumbItem.label + (last ? ' (p\u00E1gina atual)' : '')\n                        \"\n                    >\n                        @if (breadcrumbItem.icon && !(first && breadcrumbItem.disabledIcon)) {\n                            <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n                        }\n                        @if (breadcrumbItem.label && !breadcrumbItem.hideLabel) {\n                            <span>{{ breadcrumbItem.label }}</span>\n                            <span class=\"sr-only\"> (navega\u00E7\u00E3o interna)</span>\n                        }\n                    </a>\n                } @else {\n                    <span\n                        class=\"flex items-center gap-1\"\n                        [attr.aria-current]=\"last ? 'page' : null\"\n                    >\n                        @if (breadcrumbItem.icon && !(first && breadcrumbItem.disabledIcon)) {\n                            <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n                        }\n                        @if (breadcrumbItem.label && !breadcrumbItem.hideLabel && !first) {\n                            <span>{{ breadcrumbItem.label }}</span>\n                        }\n                    </span>\n                }\n            </li>\n        }\n    </ol>\n</nav>\n\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i2.TranslatePipe, name: "translate" }, { kind: "directive", type: InteractiveContentDirective, selector: "[sInteractiveContent]", inputs: ["focusable", "disabled", "stopPropagation"], outputs: ["sInteractiveContent"] }, { kind: "ngmodule", type: RouterModule }, { kind: "directive", type: i3.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: BreadcrumbListComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-breadcrumb-list', standalone: true, imports: [CommonModule, TranslateModule, InteractiveContentDirective, RouterModule], template: "<nav\n    [attr.aria-label]=\"'platform.angular_components.breadcrumb_aria_label' | translate\"\n    class=\"mb-4 mt-4\"\n>\n    <ol class=\"flex select-none flex-wrap items-center gap-3 pb-3 pt-3 [&_li]:font-open-sans [&_li]:text-sm\">\n        @for (breadcrumbItem of items(); track $index; let first = $first; let last = $last) {\n            <li class=\"flex items-center gap-3\">\n                @if (!first) {\n                    <i\n                        class=\"fas fa-chevron-right\"\n                        aria-hidden=\"true\"\n                    ></i>\n                }\n\n                <ng-template #iconTemplate>\n                    <i\n                        [class]=\"breadcrumbItem.icon + (first ? ' text-criticality-blue' : '')\"\n                        aria-hidden=\"true\"\n                    ></i>\n                </ng-template>\n\n                @if (first && breadcrumbItem.icon && breadcrumbItem.disabledIcon) {\n                    <span\n                        class=\"flex items-center gap-1\"\n                        aria-hidden=\"true\"\n                    >\n                        <i\n                            [class]=\"breadcrumbItem.icon + ' text-grayscale-30'\"\n                            aria-hidden=\"true\"\n                        ></i>\n                    </span>\n                }\n\n                @if (breadcrumbItem.url) {\n                    <a\n                        [href]=\"breadcrumbItem.url\"\n                        [target]=\"breadcrumbItem.target\"\n                        class=\"flex items-center gap-1 text-criticality-blue\"\n                        [attr.aria-current]=\"last ? 'page' : null\"\n                        [attr.aria-label]=\"\n                            (first ? 'In\u00EDcio: ' : 'Navegar para ') +\n                            breadcrumbItem.label +\n                            (last ? ' (p\u00E1gina atual)' : '')\n                        \"\n                    >\n                        @if (breadcrumbItem.icon && !(first && breadcrumbItem.disabledIcon)) {\n                            <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n                        }\n                        @if (breadcrumbItem.label && !breadcrumbItem.hideLabel && !first) {\n                            <span>{{ breadcrumbItem.label }}</span>\n                            <span class=\"sr-only\"> (link externo)</span>\n                        }\n                    </a>\n                } @else if (breadcrumbItem.routerLink && !breadcrumbItem.disabled) {\n                    <a\n                        [routerLink]=\"breadcrumbItem.routerLink\"\n                        [queryParams]=\"breadcrumbItem.queryParams\"\n                        [queryParamsHandling]=\"breadcrumbItem.queryParams ? null : 'preserve'\"\n                        [target]=\"breadcrumbItem.target\"\n                        (sInteractiveContent)=\"onActivateRoute(breadcrumbItem)\"\n                        class=\"flex cursor-pointer items-center gap-1 text-primary hover:no-underline\"\n                        [attr.aria-current]=\"last ? 'page' : null\"\n                        [attr.aria-label]=\"\n                            (first ? 'In\u00EDcio: ' : '') + breadcrumbItem.label + (last ? ' (p\u00E1gina atual)' : '')\n                        \"\n                    >\n                        @if (breadcrumbItem.icon && !(first && breadcrumbItem.disabledIcon)) {\n                            <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n                        }\n                        @if (breadcrumbItem.label && !breadcrumbItem.hideLabel) {\n                            <span>{{ breadcrumbItem.label }}</span>\n                            <span class=\"sr-only\"> (navega\u00E7\u00E3o interna)</span>\n                        }\n                    </a>\n                } @else {\n                    <span\n                        class=\"flex items-center gap-1\"\n                        [attr.aria-current]=\"last ? 'page' : null\"\n                    >\n                        @if (breadcrumbItem.icon && !(first && breadcrumbItem.disabledIcon)) {\n                            <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n                        }\n                        @if (breadcrumbItem.label && !breadcrumbItem.hideLabel && !first) {\n                            <span>{{ breadcrumbItem.label }}</span>\n                        }\n                    </span>\n                }\n            </li>\n        }\n    </ol>\n</nav>\n\n" }]
        }] });

class DynamicBreadcrumbComponent {
    _activatedRoute = inject(ActivatedRoute);
    _router = inject(Router);
    homeUrl;
    targetHomeUrl = '_self';
    items = [];
    title;
    _ngUnsubscribe = new Subject();
    constructor() {
        this._router.events
            .pipe(takeUntil(this._ngUnsubscribe), filter((event) => event instanceof NavigationEnd))
            .subscribe(() => this._onNavigationEnd());
    }
    ngOnDestroy() {
        this._ngUnsubscribe.next();
        this._ngUnsubscribe.complete();
    }
    _onNavigationEnd() {
        const currentRoute = this._activatedRoute.root;
        const validRoutes = this._getValidChildren(currentRoute);
        this.title = this._getCurrentTitle(validRoutes) ?? '';
        this.items = this._getCurrentItems(validRoutes) || [];
        const currentHome = this._getCurrentHome(validRoutes);
        if (currentHome) {
            this.items.unshift(currentHome);
        }
    }
    _getValidChildren(route) {
        const valid = route.routeConfig?.path && route.routeConfig?.component && route.outlet === PRIMARY_OUTLET;
        return route.children.reduce((validRoutes, child) => [...validRoutes, ...this._getValidChildren(child)], valid ? [route] : []);
    }
    _getCurrentTitle(routes) {
        const last = routes.at(-1);
        if (last?.routeConfig) {
            return this._getTitle(last);
        }
        return null;
    }
    _getCurrentHome(routes) {
        let currentHome;
        if (this.homeUrl) {
            currentHome = { url: this.homeUrl, icon: 'fa fa-home', target: this.targetHomeUrl };
        }
        else if (routes.length) {
            currentHome = {
                ...this._getMenuItem(routes[0], routes.length === 1),
                disabledIcon: routes.length === 1,
                hideLabel: routes.length > 1,
                icon: 'fa fa-home',
            };
        }
        return currentHome;
    }
    _getCurrentItems(routes) {
        if (!routes.length) {
            return [];
        }
        const items = this.homeUrl ? routes : routes.slice(1);
        if (items.length) {
            return items.map((route, i) => this._getMenuItem(route, i === items.length - 1));
        }
        return [];
    }
    _getMenuItem(route, disabled = false) {
        const label = this._getTitle(route);
        const routerLink = ['/', ...route.pathFromRoot.flatMap((item) => item.snapshot.url.map((url) => url.path))];
        return {
            disabled,
            label,
            routerLink,
            queryParams: route.snapshot.queryParams,
        };
    }
    _getTitle(route) {
        const { snapshot, routeConfig } = route;
        const title = snapshot.data['routeTitle'];
        if (!title) {
            throw new Error(`No routeTitle defined for the route /${routeConfig?.path}`);
        }
        return title;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DynamicBreadcrumbComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: DynamicBreadcrumbComponent, isStandalone: true, selector: "s-breadcrumb, s-dynamic-breadcrumb", inputs: { homeUrl: "homeUrl", targetHomeUrl: "targetHomeUrl" }, providers: [
            {
                provide: DEPRECATED_CONFIG,
                useValue: {
                    oldSelector: 's-breadcrumb',
                    newSelector: 's-dynamic-breadcrumb',
                    removalVersion: '20.0.0',
                },
            },
        ], hostDirectives: [{ directive: i1$1.DeprecatedSelectorDirective }], ngImport: i0, template: "<h1 class=\"sds-page-title\">{{ title }}</h1>\n<s-breadcrumb-list [items]=\"items\" />\n\n", dependencies: [{ kind: "component", type: BreadcrumbListComponent, selector: "s-breadcrumb-list", inputs: ["items"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DynamicBreadcrumbComponent, decorators: [{
            type: Component,
            args: [{ standalone: true, imports: [BreadcrumbListComponent], selector: 's-breadcrumb, s-dynamic-breadcrumb', hostDirectives: [DeprecatedSelectorDirective], providers: [
                        {
                            provide: DEPRECATED_CONFIG,
                            useValue: {
                                oldSelector: 's-breadcrumb',
                                newSelector: 's-dynamic-breadcrumb',
                                removalVersion: '20.0.0',
                            },
                        },
                    ], template: "<h1 class=\"sds-page-title\">{{ title }}</h1>\n<s-breadcrumb-list [items]=\"items\" />\n\n" }]
        }], ctorParameters: () => [], propDecorators: { homeUrl: [{
                type: Input
            }], targetHomeUrl: [{
                type: Input
            }] } });

/**
 * @deprecated utilizar DynamicBreadcrumbComponent (standalone)
 */
class BreadcrumbModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: BreadcrumbModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: BreadcrumbModule, imports: [DynamicBreadcrumbComponent], exports: [DynamicBreadcrumbComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: BreadcrumbModule, imports: [DynamicBreadcrumbComponent] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: BreadcrumbModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [DynamicBreadcrumbComponent],
                    exports: [DynamicBreadcrumbComponent],
                }]
        }] });

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

export { BreadcrumbListComponent, BreadcrumbModule, DynamicBreadcrumbComponent };
//# sourceMappingURL=seniorsistemas-angular-components-breadcrumb.mjs.map
