using Avalonia.Controls; using Avalonia.Input.Platform; using Avalonia.Interactivity; using LehrerApp.Desktop.Services; using LehrerApp.Desktop.ViewModels.Groups; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Groups; public partial class AiAssistDialog : Window { public AiAssistDialog() => InitializeComponent(); private async void OnCopyMaterialPrompt(object? s, RoutedEventArgs e) { if (s is not Button { DataContext: MaterialPromptItem item }) return; var clipboard = TopLevel.GetTopLevel(this)?.Clipboard; if (clipboard is null) return; await clipboard.SetTextAsync(item.PromptText); App.Services.GetRequiredService().ShowSuccess("Prompt in die Zwischenablage kopiert."); } private async void OnSend(object? s, RoutedEventArgs e) { if (DataContext is AiAssistDialogViewModel vm && vm.SendCommand.CanExecute(null)) await vm.SendCommand.ExecuteAsync(null); } private async void OnRescue(object? s, RoutedEventArgs e) { if (DataContext is not AiAssistDialogViewModel { RawResponse: { } raw } vm) return; var rescueVm = new AiResponseRescueDialogViewModel( App.Services.GetRequiredService(), App.Services.GetRequiredService(), vm.Unit, raw, vm.FocusLessonId); var rescue = new AiResponseRescueDialog { DataContext = rescueVm }; if (await rescue.ShowDialog(this)) { vm.MarkRescueImported(); Close(true); } } private void OnApply(object? s, RoutedEventArgs e) { if (DataContext is AiAssistDialogViewModel vm && vm.ApplyCommand.CanExecute(null)) { vm.ApplyCommand.Execute(null); Close(true); } } private void OnCancel(object? s, RoutedEventArgs e) { if (DataContext is AiAssistDialogViewModel vm) vm.CancelCommand.Execute(null); Close(false); } }