private void Button_Search(object sender, RoutedEventArgs e)
        {
            GetMoviesFromApi.RetrieveMoviesFromApi(); // Refresh the app
            //  WishlistGrid.ItemsSource = GetMoviesFromApi();
            if (search.Text == "")
            {
                MessageBox.Show("Please type a movie title");
            }

            int i = 0;

            while (i < moviesList.ToArray().Length)
            {
                if (search.Text.ToLower() == moviesList[i].Title.ToLower())
                {
                    MessageBox.Show("Movie found!\n\nPlease click Add button to add it to your wishlist");
                    addMovieButton.IsEnabled = true;

                    break;
                }
                i++;
            }
            //MessageBox.Show($"{i}");

            if (i == moviesList.ToArray().Length&& search.Text != "")
            {
                MessageBox.Show("OOps! Not found. \n\nPlease search for aother movie");
            }
        }
        private void Button_ShowDetail(object sender, RoutedEventArgs e)
        {
            if (WishlistGrid.SelectedIndex < 0)
            {
                MessageBox.Show("Please click one movie in your wishlist");
            }
            else
            {
                GetMoviesFromApi.RetrieveMoviesFromApi();
                GetWishlistFromApi.RetrieveSavedMoviesFromApi();

                for (int j = 0; j < moviesList.Count; j++)
                {
                    if (noDuplicateTitles[WishlistGrid.SelectedIndex] == moviesList[j].Title)
                    {
                        // MessageBox.Show($"{noDuplicateTitles[WishlistGrid.SelectedIndex]}");
                        // MessageBox.Show($"{moviesList[j - 1].Title}");

                        title.Text     = $"{moviesList[j].Title}";
                        summary.Text   = $"{moviesList[j].Summary}";
                        genre.Text     = $"{moviesList[j].Genre}";
                        rating.Text    = $"{moviesList[j].Rating}";
                        Picture.Source = new BitmapImage(new Uri(@"https://m.media-amazon.com/images/M/" + moviesList[j].Picture, UriKind.Absolute));
                    }
                }
            }
        }
        private void Button_Remove(object sender, RoutedEventArgs e)
        {
            //  WishlistGrid.ItemsSource = GetNoDuplicateTitles();

            GetMoviesFromApi.RetrieveMoviesFromApi(); // Refresh the app

            int personId = int.Parse(userId.Text);

            // MessageBox.Show($"{WishlistGrid.SelectedIndex}");

            if (WishlistGrid.SelectedIndex < 0)
            {
                MessageBox.Show("Please click one movie in your wishlist");

                DisplayNoDetails();
            }
            else
            {
                //GetWishlistTitles();
                //GetNoDuplicateTitles();
                //int x = wishList[WishlistGrid.SelectedIndex].Mid;
                //string newTitle = moviesList[x-1].Title;

                List <string> titles = GetNoDuplicateTitles();

                // titles.Add(newTitle);

                // MessageBox.Show($"{titles[WishlistGrid.SelectedIndex]}");
                // MessageBox.Show($"{moviesList[3].Title}");

                // List<string> titles = GetWishlistTitles();

                for (int j = 0; j < moviesList.Count; j++)
                {
                    WishlistGrid.ItemsSource = GetNoDuplicateTitles();
                    int z = WishlistGrid.SelectedIndex;
                    if (z >= 0 & titles[z] == moviesList[j + 1].Title)     // index still out of range sometimes :(
                    {
                        int MIdFound = Array.FindIndex(moviesList.ToArray(), row => row.Title == titles[z]);

                        int IdFound = Array.FindIndex(wishList.ToArray(), row => row.Mid == (MIdFound + 1));

                        //  MessageBox.Show($"{MIdFound + 1}");

                        //  MessageBox.Show($"{IdFound}");


                        int id = wishList[IdFound].Id;

                        DeleteWishlist.DeleteSavedMovie(id, personId, (MIdFound + 1));


                        MessageBox.Show("Movie has been removed");

                        // MessageBox.Show($"{noDuplicateTitles[WishlistGrid.SelectedIndex]}");
                        // MessageBox.Show($"{moviesList[j - 1].Title}");

                        DisplayNoDetails();


                        for (int i = 0; i < wishList.Count; i++)
                        {
                            if (wishList[i].Mid == (MIdFound + 1) && wishList[i].Pid == personId)
                            {
                                string item = moviesList[MIdFound].Title;

                                //  MessageBox.Show($"{item}");

                                titles.Remove(item);


                                WishlistGrid.ItemsSource = titles; // Also remove the title from UI
                            }
                        }
                        break;
                    }
                }
            }
        }