using galacticlip_app.Models; using System; using System.Windows.Input; using Microsoft.Maui.Controls; namespace galacticlip_app { public class MediaDetailViewModel : BindableObject { private const string NoteKeyPrefix = "MediaNote_"; public string ThumbnailUrl { get; private set; } public string Title { get; private set; } public string Description { get; private set; } public DateTime DateCreated { get; private set; } public string Photographer { get; private set; } public string Keywords { get; private set; } private string _personalNote; public string PersonalNote { get => _personalNote; set { if (_personalNote != value) { _personalNote = value; OnPropertyChanged(); // Save the note whenever it changes SavePersonalNote(); } } } public ICommand BookmarkCommand { get; } public ICommand CloseCommand { get; } private string _noteKey; // Updated constructor to accept a NasaMediaItem directly public MediaDetailViewModel(NasaMediaItem mediaItem) { if (mediaItem != null) { ThumbnailUrl = mediaItem.ThumbnailUrl; Title = mediaItem.Title; Description = mediaItem.Description; DateCreated = mediaItem.DateCreated; Photographer = mediaItem.Photographer; Keywords = mediaItem.Keywords; // Use the item's unique identifier as the key _noteKey = $"{NoteKeyPrefix}{mediaItem.Id}"; // Load saved note for this media item PersonalNote = Preferences.Get(_noteKey, string.Empty); } BookmarkCommand = new Command(OnBookmark); CloseCommand = new Command(OnClose); } private void SavePersonalNote() { Preferences.Set(_noteKey, _personalNote); } private async void OnBookmark() { await App.Current.MainPage.DisplayAlert("Bookmark", "Item bookmarked successfully.", "OK"); } private async void OnClose() { await App.Current.MainPage.Navigation.PopModalAsync(); } } }