import { Component, inject, output } from '@angular/core'; import { CommonModule } from '@angular/common'; import { firstValueFrom } from 'rxjs'; import { HistoryEntry } from '../interfaces/history-entry'; import { HistoryEntryService } from '../services/history-entry.service'; @Component({ selector: 'app-admin-history-tab', standalone: true, imports: [CommonModule], templateUrl: './admin-history-tab.component.html', styleUrl: './admin-history-tab.component.scss', }) export class AdminHistoryTabComponent { private historyEntryService = inject(HistoryEntryService); readonly openForm = output(); readonly editItem = output(); readonly deleteItem = output(); readonly entries$ = this.historyEntryService.getHistoryEntries(); ngOnInit(): void { this.load(); } async load(): Promise { await firstValueFrom(this.historyEntryService.getHistoryEntries()); } onAdd(): void { this.openForm.emit(); } onEdit(entry: HistoryEntry): void { this.editItem.emit(entry); } async onDelete(id: number): Promise { if (!confirm('Delete this history entry?')) return; await firstValueFrom(this.historyEntryService.deleteHistoryEntry(id)); await this.load(); } }