using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UP_Session1_Belov.Models;

namespace UP_Session1_Belov.Pages
{
    /// <summary>
    /// Логика взаимодействия для ProductListPage.xaml
    /// </summary>
    public partial class ProductListPage : Page
    {
        private static ProductListModel listProducts = new ProductListModel();
        public ProductListPage()
        {
            InitializeComponent();

            DataContext = listProducts;
           
        }

        private void filtres_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           listProducts.Sort();
        }

        private void Image_Loaded(object sender, RoutedEventArgs e)
        {
            Image image = (Image)sender;
            image.Source = new BitmapImage(new Uri("\\Resources\\" + image.DataContext, UriKind.Relative));
        }

        private void TextBlock_Loaded(object sender, RoutedEventArgs e)
        {
            TextBlock textBlock = (TextBlock)sender;

            if (textBlock.Text != "" && textBlock.Text != null)
            {
                double discount = Convert.ToDouble(textBlock.Text);

                var bc = new BrushConverter();

                if (discount > 15)
                {
                    textBlock.Background = (Brush)bc.ConvertFrom("#7fff00");
                }
            }
        }

        private void SearchFilter_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (DataContext is ProductListModel viewModel)
            {
                viewModel.Search = SearchFilter.Text;
            }
        }
    }
}
