gehgassi_app/gehGassiApp/gehGassiApp/ViewModels/Popups/SubscriptionSuccessPopupViewModel.cs
2025-08-14 10:34:58 +02:00

75 lines
2.1 KiB
C#

using CommunityToolkit.Maui;
using CommunityToolkit.Maui.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using gehGassiApp.Models.PopupResults;
namespace gehGassiApp.ViewModels.Popups;
public partial class SubscriptionSuccessPopupViewModel : ObservableObject, IQueryAttributable
{
#region Constants
private const string STRAYZ_URL = "https://www.strayz.de/pages/fuer-hunde";
#endregion
#region Dependencies
private readonly IPopupService _popupService;
#endregion
#region Constructor
public SubscriptionSuccessPopupViewModel(IPopupService popupService)
{
_popupService = popupService;
}
#endregion
#region IQueryAttributable Implementation
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
// Falls Parameter benötigt werden, hier implementieren
}
#endregion
#region Commands
/// <summary>
/// Öffnet die STRAYZ-Partnerseite
/// </summary>
[RelayCommand]
private async Task OpenStrayz()
{
try
{
// Öffne STRAYZ-Seite im Browser
await Browser.OpenAsync(STRAYZ_URL, BrowserLaunchMode.External);
var result = SubscriptionSuccessResult.StrayzOpened();
// Popup schließen mit Result
await _popupService.ClosePopupAsync(Shell.Current, result);
}
catch (Exception ex)
{
// Fehlerbehandlung
await Shell.Current.DisplayAlert(
"Fehler",
"Die STRAYZ-Seite konnte nicht geöffnet werden. Bitte versuche es später erneut oder besuche strayz.de direkt.",
"OK");
System.Diagnostics.Debug.WriteLine($"Error opening STRAYZ URL: {ex.Message}");
}
}
/// <summary>
/// Popup schließen ohne STRAYZ zu öffnen
/// </summary>
[RelayCommand]
private async Task Close()
{
var result = SubscriptionSuccessResult.Closed();
// Popup schließen mit Result
await _popupService.ClosePopupAsync(Shell.Current, result);
}
#endregion
}