import { Component, inject, ChangeDetectionStrategy } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog'; import { MatIconModule } from '@angular/material/icon'; import { TranslateModule } from '@ngx-translate/core'; /** What the user picked; closing via backdrop/Esc yields `undefined` = stay. */ export type SettingsUnsavedChangesChoice = 'save' | 'discard'; export interface SettingsUnsavedChangesDialogData { /** Save-and-leave is offered only while the form can actually be saved. */ canSave: boolean; } /** * Asked once, when the user is about to leave the settings area with staged * edits. Section switches never show this — the shared form survives them. * "Cancel" (stay) carries the initial focus so Enter is always the safe * choice. Labels are single verbs so the row fits one line in every locale. */ @Component({ imports: [MatButtonModule, MatDialogModule, MatIconModule, TranslateModule], styles: [ ` .unsaved-dialog__invalid-hint { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; color: var(--mat-sys-error); font-size: 0.86rem; mat-icon { font-size: 18px; width: 18px; height: 18px; } } /* Phone breakpoint: one full-width action per row, in DOM order, instead of letting a long translation wrap the row unevenly. */ @media (max-width: 640px) { .unsaved-dialog__actions { flex-direction: column; align-items: stretch; gap: 8px; } .unsaved-dialog__actions .mat-mdc-button-base + .mat-mdc-button-base { margin: 0; } } `, ], changeDetection: ChangeDetectionStrategy.OnPush, template: `

{{ 'SETTINGS.UNSAVED_DIALOG_TITLE' | translate }}

{{ 'SETTINGS.UNSAVED_DIALOG_MESSAGE' | translate }}

@if (!data.canSave) {

error_outline {{ 'SETTINGS.UNSAVED_DIALOG_INVALID_HINT' | translate }}

}
`, }) export class SettingsUnsavedChangesDialogComponent { readonly data = inject(MAT_DIALOG_DATA); }