using Avalonia.Controls; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; using LehrerApp.Desktop.ViewModels.Groups; using LehrerApp.Desktop.ViewModels.Students; using LehrerApp.Desktop.Views.Shared; using LehrerApp.Desktop.Views.Students; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Groups; public partial class GroupDocumentationTabView : UserControl { public GroupDocumentationTabView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is not GroupDocumentationTabViewModel vm) return; vm.OnEditDocumentation = ShowDocumentationDialog; vm.OnConfirmDeleteDocumentation = ShowDeleteDocumentationDialog; vm.OnConductParentCall = ShowParentCallSessionDialog; } private async Task ShowDocumentationDialog( Guid groupId, List studentOptions, Documentation? editing) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return null; var vm = new DocumentationDialogViewModel(editing?.StudentId ?? Guid.Empty, editing, App.Services.GetRequiredService(), studentOptions, groupId); var dialog = new DocumentationDialog { DataContext = vm }; var saved = await dialog.ShowDialog(owner); if (!saved) vm.DiscardUnsavedAttachments(); return saved ? vm.Result : null; } private async Task ShowParentCallSessionDialog(Documentation documentation, string studentTitle) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return null; var vm = new ParentCallSessionViewModel(documentation, studentTitle); var dialog = new ParentCallSessionDialog { DataContext = vm }; var saved = await dialog.ShowDialog(owner); return saved ? vm.Result : null; } private async Task ShowDeleteDocumentationDialog(DocumentationItem item) { var info = new ConfirmDialogInfo { Title = "Eintrag löschen?", Message = $"\"{item.Model.Title}\" ({item.StudentName}) wird als gelöscht markiert und nicht mehr angezeigt.", ConfirmText = "Löschen", }; var dialog = new ConfirmDialog { DataContext = info }; var owner = TopLevel.GetTopLevel(this) as Window; return owner is not null && await dialog.ShowDialog(owner); } }