using Sessioa.BaseModel;
using Sessioa.Classes;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Sessioa.Pages
{
    /// <summary>
    /// Логика взаимодействия для ProductsPage.xaml
    /// </summary>
    public partial class ProductsPage : Page
    {
        public ProductsPage()
        {
            InitializeComponent();
            LB_Product.ItemsSource = BaseClass.C_Base.Product.ToList();
        }

        private void countPr_Loaded(object sender, RoutedEventArgs e)
        {
            TextBlock tb = (TextBlock)sender;
            Product product = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == tb.Uid);
            if (product.ProductDiscountAmount != null || product.ProductDiscountAmount != 0)
                tb.TextDecorations = TextDecorations.Strikethrough;
        }

        private void countPr_Loaded_1(object sender, RoutedEventArgs e)
        {
            TextBlock tb = (TextBlock)sender;
            Product product = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == tb.Uid);
            if (product.ProductDiscountAmount != null && product.ProductDiscountAmount != 0)
            {
                double j = (double)product.ProductDiscountAmount / 100;
                double ji = (double)(product.ProductCost) * j;

                double n = (double)(product.ProductCost) - ji;
                tb.Text = n.ToString() + "$";
                tb.Visibility = Visibility.Visible;
            }
        }

        private void Border_Loaded(object sender, RoutedEventArgs e)
        {
            Border border = (Border)sender;
            Product product = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == border.Uid);
            if (product.ProductDiscountAmount != null && product.ProductDiscountAmount > 15)
                border.Background = (Brush)(new BrushConverter().ConvertFrom("#7fff00"));
        }

        private void Discount_Loaded(object sender, RoutedEventArgs e)
        {
            TextBlock tb = (TextBlock)sender;
            Product product = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == tb.Uid);
            if (product.ProductDiscountAmount != null && product.ProductDiscountAmount != 0)
                tb.Text = $"Скидка {product.ProductDiscountAmount}%";
        }
    }
}
