using Avalonia.Controls; using Avalonia.Interactivity; using LehrerApp.Desktop.Services; using LehrerApp.Desktop.ViewModels.Groups; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Groups; public partial class CompetencyOverviewTabView : UserControl { public CompetencyOverviewTabView() => InitializeComponent(); private async void OnExportPdfClick(object? sender, RoutedEventArgs e) { var topLevel = TopLevel.GetTopLevel(this); if (topLevel is null || DataContext is not CompetencyOverviewTabViewModel { HasRows: true } vm) return; var studentName = vm.SelectedStudent?.DisplayName ?? "Kein Schüler ausgewählt"; var data = new CompetencyReportPrintData(vm.GroupLabel, studentName, vm.Summary, vm.ThresholdLabel, vm.Rows.Select(r => new CompetencyReportPrintRow(r.Domain, r.Code, r.Description, r.InstructionCoverage, r.ExamCoverage, r.GroupResult, r.StudentResult, r.Recommendation)).ToList()); var pdf = App.Services.GetRequiredService().BuildCompetencyReportPdf(data); await App.Services.GetRequiredService().SaveAsync(topLevel.StorageProvider, ExportFile.Pdf("Kompetenzbericht als PDF speichern", $"Kompetenzbericht_{vm.GroupLabel}_{studentName}", pdf)); } }