import { Component, computed, inject } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet } from '@angular/router'; import { MatButtonModule } from '@angular/material/button'; import { MatMenuModule } from '@angular/material/menu'; import { filter, map } from 'rxjs'; import { Dominio, DOMINIOS } from './features/indicadores/indicadores.models'; @Component({ imports: [RouterLink, RouterOutlet, MatButtonModule, MatMenuModule], selector: 'app-root', styleUrl: './app.scss', templateUrl: './app.html', }) export class App { private readonly router = inject(Router); private readonly route = inject(ActivatedRoute); private readonly leafRouteData = toSignal( this.router.events.pipe( filter((event) => event instanceof NavigationEnd), map(() => { let route = this.route; while (route.firstChild) route = route.firstChild; return route.snapshot.data; }), ), { initialValue: {} as Record }, ); /** Full-height workspace routes (`data.workspace`) drop the marketing footer. */ readonly workspace = computed(() => !!this.leafRouteData()['workspace']); readonly breadcrumb = computed(() => this.leafRouteData()['breadcrumb'] as string | undefined); protected readonly title = 'Plataforma de Indicadores'; protected readonly domainLabels: Record = { tea: 'TEA', cacu: 'CaCu', cama: 'Cáncer de mama' }; private readonly url = toSignal(this.router.events.pipe( filter((event) => event instanceof NavigationEnd), map(event => event.urlAfterRedirects)), { initialValue: this.router.url }); /** On an indicators page the header names its domain and switches to the others. */ protected readonly activeDomain = computed(() => DOMINIOS.find(domain => new RegExp(`^/indicadores/${domain}(?:[/?#]|$)`).test(this.url()))); protected readonly otherDomains = computed(() => DOMINIOS.filter(domain => domain !== this.activeDomain())); }