import { Component, Input } from '@angular/core'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { MatCardModule } from '@angular/material/card'; @Component({ selector: 'app-indicador-kpi-card', imports: [MatCardModule, MatProgressBarModule], template: `

{{ title }}

@if (loading) { } @if (value !== null && value !== undefined) {

{{ value }}@if (unit) { {{ unit }} }

}
@if (showPeriod && temporalReference) {

@if (labeledPeriod) { Periodo: }{{ temporalReference }}

}

{{ state }}

@if (informationLine) {

{{ informationLine }}

}
`, styles: ` :host { display: flex; flex-direction: column; height: 100%; min-width: 0; } mat-card { box-sizing: border-box; display: flex; flex-direction: column; flex: 1 1 auto; height: auto; min-height: 100%; padding: var(--issste-space-6); background: var(--issste-surface); color: var(--issste-text); border: 1px solid var(--issste-border); border-radius: var(--issste-radius); box-shadow: none; } .kpi-foot { margin-top: auto; } .period { display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem; } .period-label { font-weight: 600; } h3 { margin: 0; font-family: var(--issste-font-heading); font-size: 1rem; font-weight: 500; line-height: 1.3; } h3, p { overflow-wrap: anywhere; } p { margin: var(--issste-space-3) 0 0; } .kpi-state, .additional-info { color: var(--issste-text-secondary); font: var(--mat-sys-body-medium); } .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; } .value { font-size: 1.75rem; font-weight: 500; line-height: 1.2; } .value span { margin-inline-start: .3em; } // CaMa's cards are as tall as their grid row. :host-context(.kpi-section[data-domain='cama']) { display: flex; flex-direction: column; } :host-context(.kpi-section[data-domain='cama']) mat-card { flex: 1 1 auto; height: auto; } :host-context(.kpi-section[data-domain='cama']) .value { font-size: 1.65rem; } `, }) export class IndicadorKpiCard { @Input({ required: true }) title!: string; @Input() value?: string | number | null; @Input() unit?: string; @Input() temporalReference?: string; // CaMa's opportunity strip shares one period, shown by the parent instead of on every card. @Input() showPeriod = true; @Input() loading = false; @Input() notes: string[] = []; @Input() state = 'Pendiente de definición'; // A card that shows its value needs no "Disponible" line. @Input() quietWhenAvailable = false; @Input() additionalInfo?: string; get labeledPeriod(): boolean { const text = this.temporalReference?.trim(); return !!text && text.split(',').every(part => /^\d{4}-(?:S[12]|0[1-9]|1[0-2])$/.test(part.trim())); } get informationLine(): string | undefined { const lines = [this.additionalInfo, ...this.notes].map(value => value?.trim()).filter((value): value is string => !!value); return [...new Set(lines)].join(' '); } }